Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate: timestamp without timezone #339

Open
isoos opened this issue May 18, 2024 · 4 comments
Open

Investigate: timestamp without timezone #339

isoos opened this issue May 18, 2024 · 4 comments

Comments

@isoos
Copy link
Owner

isoos commented May 18, 2024

It is not clear to me what should be the behavior when the server and the client have different timezones (both different than UTC). We should investigate and fix if needed.

@hendrik-brower
Copy link

I was just experimenting with ConnectionSettings, setting timezone to 'UTC' and 'America/New_York', 'EST'. Then running connection.execute with a series of statements:
select curent_timestamp;
set timezone to 'UTC';
select curent_timestamp;
set timezone to 'America/New_York';
select curent_timestamp;
set timezone to 'EST';
select curent_timestamp;
All select statements return the same string (with trailing Z) that reflects the database's timezone (ie alter database x set timezone y). This differs from the behavior I observe when running the running same queries through the psql command line utility. When running through command line utility, I get time stamps with +00, -04, -05 (reflecting the connection setting).

From this, it seems like the ConnectionSettings timezone value is not applied. It also seems like the set timezone statements do not affect the connection. Maybe each query is running in a separate session?

I think this would not be much of an issue if when retrieving a value, eg: res[0][0] as DateTime, returned a DateTime object that was a utc value. And when passing one, it converted it to utc. But it seems to return it as a local datetime, so you end up with a timeshift on the client size. Presently, to make things work as expected, I need to "insert (ct) values (@ct)" with ct=DateTime.now().toUtc(). Then after reading it, convert it to utc to get a matching result.

I haven't experimented with doing this in a session obtained via connection.run, though I would think a "connection" represents a session where as run(fn(session)) would represent a separate session. A bit more documentation on the top level classes to help outline these sorts of details would be great.

@hendrik-brower
Copy link

Just tried the same sequence with a session... same result. no returned values appear to respect the timezone set by "set timezone 'xx'" command. All values seem to be fixed to the database's setting.

@isoos
Copy link
Owner Author

isoos commented Jun 2, 2024

@hendrik-brower: thank you for looking into this! Would you be also interested in writing a fix? I'd be happy to review and guide if needed.

@hendrik-brower
Copy link

hendrik-brower commented Jun 3, 2024 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants