Same problem have. I have more complicated query but the problem is the same. It doesn't matter about details of DB, will enough that you operate with dates then results are different. I sure it is regarding time zones. When Python is trying to execute he somehow covert it into different timezone than client
Similar problem raised here: python script keeps converting dates to utc
Update: So the problem has been solved You should defined on both sides which time zone you want to use. When you use PosgreSQL client as DBeaver he is using DB timezone defined
SELECT *
FROM pg_timezone_names
WHERE name = current_setting('TIMEZONE');
So this simplified my query:
select count(id)
from realestates_realestate
where create_date::date = now()::date – 1
Should look like this:
select count(id)
from realestates_realestate
where (create_date AT TIME ZONE 'CET')::date = (now() AT TIME ZONE 'CET')::date – 1
In that case results will be the same, cause Python is executing query on different timezone (as it seem to me on UTC time zone). When you define in SQL which time zone use then problem solved.