Anh Đỗ
Anh Đỗ

Reputation: 1

ActiveRecord::Base.connection.execute and pure sql return different result

I use ActiveRecord::Base.connection.execute and pure sql with the same query but the results are different. Has anyone encountered such as my case yet? I use postgresql 9.6 and activerecord 5.2.3

my_query:

SELECT history_id, timestamp
FROM xxx
 WHERE (
 timestamp >= TO_TIMESTAMP('2002/07/17 00:00:00', 'YYYY/mm/DD HH24:MI:SS') AND
 timestamp < TO_TIMESTAMP('2002/07/23 00:00:00', 'YYYY/mm/DD HH24:MI:SS') +'1 day'::interval
 --
 )

I query with ActiveRecord by: ActiveRecord::Base.connection.execute(my_query) The result have record with timestamp in 2002/07/24. Those do not appear when I query with pure SQL.

My timestamp column in xxx table have type: timestamp with time zone

Upvotes: -2

Views: 210

Answers (1)

Anh Đỗ
Anh Đỗ

Reputation: 1

The problem is the default_timezone in ActiveRecord and timezone in psql is different. That's all :))

Upvotes: 0

Related Questions