Odoo 17 Development Book- SQL Execution

SQL Execution

The cr property on environments represents the cursor for the current database transaction.

It enables you to execute SQL directly instead of through the ORM, which is beneficial for queries that are difficult to construct using the ORM. (e.g., complex joins) or for performance reasons:

self.env.cr.execute("some_sql", params)

While all models use the same cursor and the environment has a variety of caches, updating the database in raw SQL necessitates destroying these caches, or else the model use would become nonsensical. When using CREATE, UPDATE, or DELETE in SQL, clearing caches is necessary, but not when using SELECT (which merely reads the database).

The invalidate cache() method can be used to clean caches.

invalidate_cache(fnames=None, ids=None)

Invalidate the record caches when some records have been changed. The whole cache is cleaned out if both fnames and ids are None.


fnames – The changed fields list, or None for every field.

ids – The changed record id list, or None for every record.



Cybrosys Technologies Pvt. Ltd.
Neospace, Kinfra Techno Park
Kakkancherry, Calicut
Kerala, India - 673635



Cybrosys Technologies Pvt. Ltd.
1st Floor, Thapasya Building,
Infopark, Kakkanad,
Kochi, India - 682030.



Cybrosys Techno Solutions
The Estate, 8th Floor,
Dickenson Road,
Bangalore, India - 560042

Send Us A Message