The column created in Postgres is:
used_at timestamp with time zone NOT NULL,
The value in Postgres is saved without timezone (in UTC):
2022-06-30 22:49:03.970913+00
Using this query:
show timezone
I get:
Etc/UTC
But from Ent (using pgx stdlib) I get the value:
2022-07-01T00:49:03.970913+02:00
Using pgdriver/pq I get the UTC value from DB.
How can I setup pgx to get UTC value?
I tried using this connection string with this code too:
import (
"database/sql"
_ "github.com/jackc/pgx/v4/stdlib"
)
conn, err := sql.Open("pgx", "postgres://postgres:postgres@localhost/project?sslmode=disable&timezone=UTC")
//handle err
The problem is still here.
I need a way to get back from DB the UTC values (that are laready stored in the DB).
timezoneis not a valid parameter key word.You can however use the
optionskey word to specify command-line options to send to the server at connection start. Just keep in mind that you need to percent encode the values therein.Example of how to set the
TimeZone:However this only enforces the connection's timezone which does not seem to have an effect on how
pgxparses the timestamps themselves once read from the database. In fact it seems it relies, directly or indirectly, on the host machine's local timezone. To confirm that you can update the globaltime.Localvariable to UTC and observe the difference.For obvious reasons I'd avoid doing the above. If
pgxdoesn't provide a way to configure the default location it uses to parse the timestamps then the next best option, that I can think of, would be to use a customtime.Timetype.