You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
My environment is gorm + postgresql + italy GMT+2 (dst).
While messing around with queries with time.Time I had to debug a query where I pass the same time.Time type parameter to use that in a where against two fields of a record of type timestamp and of type timestamptz ex:
-- Example tablecreatetabletmp
(
t timestamp without time zone,
ttz timestamp with time zone
);
golang query
db.Debug().Raw(`select * from tmp where ttz = ? or ttz = ?`, time.Now(), time.Now()).Take(&row)
At this point the gorm logger produces this output:
[0.235ms] [rows:0] select * from tmp where ttz = '2023-09-01 17:14:48.271' or ttz = '2023-09-01 17:14:48.271'
while the Postgres query logger (SELECT set_config('log_statement', 'all', false))
LOG: execute stmtcache_5: select * from tmp where ttz = $1 or ttz = $2
DETAIL: parameters: $1 = '2023-09-01 15:14:48.271574+00', $2 = '2023-09-01 15:14:48.271574+00'
The difference here is that gorm logger returns a statement where time has not the timezone, postgres logger instead show that the query has been executed with correct data; if I execute the gorm logged query as is from gorm logger, since it's missing the timezone indication/correction (as the one of postgres) I'll not get the same result that instead the server is correctly returning.
Examining gorm codebase I see that in file gorm/logger/sql.go there is the date format
that will not show timezone while producing debugged sql output, is that intentional and I have to understand that such logging is producing a query that actually will be different than the server generated one (hence possibily producing different output than expected) or could be that a bug?
thx for reading
The text was updated successfully, but these errors were encountered:
eymerich
changed the title
[Question] Query logging/debug produced sql output inconsistent with the server executed query
[Question] Query logging/debug produces sql output inconsistent with the server executed query
Sep 1, 2023
My environment is gorm + postgresql + italy GMT+2 (dst).
While messing around with queries with time.Time I had to debug a query where I pass the same time.Time type parameter to use that in a where against two fields of a record of type timestamp and of type timestamptz ex:
golang query
At this point the gorm logger produces this output:
while the Postgres query logger (
SELECT set_config('log_statement', 'all', false)
)The difference here is that gorm logger returns a statement where time has not the timezone, postgres logger instead show that the query has been executed with correct data; if I execute the gorm logged query as is from gorm logger, since it's missing the timezone indication/correction (as the one of postgres) I'll not get the same result that instead the server is correctly returning.
Examining gorm codebase I see that in file gorm/logger/sql.go there is the date format
that will not show timezone while producing debugged sql output, is that intentional and I have to understand that such logging is producing a query that actually will be different than the server generated one (hence possibily producing different output than expected) or could be that a bug?
thx for reading
The text was updated successfully, but these errors were encountered: