Closed sebastian-motavita closed 1 week ago
The connection’s time zone affects things like the default cast of a timestamp
to timestamptz
, but JavaScript Date
objects don’t have a time zone. (If you used .toString()
, you’d see your local time instead of UTC.)
You might be interested in casting the value to text
on the server with now()::text
.
That's definitely the reason, thank you, @charmander. Just as a follow up, I used the solution mentioned here to avoid the now()::text
or .toString()
:
pg.types.setTypeParser(pg.types.builtins.TIME, (timeStr) => timeStr);
pg.types.setTypeParser(pg.types.builtins.TIMESTAMP, (timeStr) => timeStr);
pg.types.setTypeParser(pg.types.builtins.TIMESTAMPTZ, (timeStr) => timeStr);
Hello, I'm dealing with the Timezone setup for my app:
I'm using
"pg": "^8.11.5",
andPostgreSQL 16.2
DB version. Everything runs just fine, except when I'm trying to set a session TimeZone. In a SQL editor, you can set the TimeZone using:And similarly, that's what this documentation on Pool events suggests to do:
However, that's not the case, the subsequent queries containing timestamp fields will yield the timestamp in UTC. For instance, with the configuration above, the next query will yield the timezone:
But I'm expecting the returned timestamp to be
2024-06-19T14:13:11.919Z
I was able to verify the event was indeed called: I changed the TimeZone to
'America/Bogotaaaa'
, which raises an error in the DB as it's a non valid TimeZone:Finally, I also tried to create a pool instance using this configuration: