Filter sql (*) counter using SQLAlchemy

How can I execute the following SQL query using SQLAlchemy?

SELECT COUNT (*) FROM det_factura WHERE company = 31 AND date::text LIKE '2011-05% '; 
+6
source share
1 answer

If det_factura also a mapped object, then this request should do this:

 qry = (session.query(func.count(det_factura.id)) .filter(det_factura.company==31) .filter(det_factura.date.like('2010-05%')) ) 

If this is an instance of table , that should work below:

 qry = select([func.count(det_factura.id)], and_(det_factura.company==31, det_factura.date.like('2010-05%') ) ) 
+6
source

Source: https://habr.com/ru/post/905995/


All Articles