PGTZ environment variable is not respected
See original GitHub issue- asyncpg version: 0.27.0
- PostgreSQL version: 14.5
- Do you use a PostgreSQL SaaS? If so, which? Can you reproduce the issue with a local PostgreSQL install?: Not SaaS
- Python version: 3.11.0
- Platform: macOS
- Do you use pgbouncer?: bi
- Did you install asyncpg with pip?: yes
- If you built asyncpg locally, which version of Cython did you use?: Install by wheel
- Can the issue be reproduced under both asyncio and uvloop?: Yes
Setting PGTZ
environment variable does not affect the timezone returned, for example, select now()
.
Issue Analytics
- State:
- Created 10 months ago
- Comments:5 (1 by maintainers)
Top Results From Across the Web
Documentation: 15: 34.15. Environment Variables - PostgreSQL
The following environment variables can be used to select default connection parameter values, which will be used by PQconnectdb , PQsetdbLogin and PQsetdb ......
Read more >Greenplum Environment Variables
The following are standard PostgreSQL environment variables, which are also recognized in Greenplum Database. You may want to add the connection-related ...
Read more >Unsupported timezone "localtime" when using the NodaTime ...
It looks like the localtime value must be set from here: var timezone = Settings.Timezone ?? Environment.GetEnvironmentVariable("PGTZ"); if ...
Read more >Databases - Practical PostgreSQL - Date and Time Types
If the PGTZ environment variable is set, it can be read by any client written with libpq and interpreted as the client's default...
Read more >How to set timezone for Postgres psql? - Stack Overflow
So, it seems you must either use the SET command inside psql, or either set the PGTZ environment variable: PGTZ=PST8PDT psql -c 'show ......
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Those environment variables are specifically for libpq. Unlike psycopg2/psycopg3, asyncpg is NOT based on libpq. We do try to maintain a certain level of compatibility with libpq, on a best effort basis. In this particular case it’s tricky because
PGTZ
andSET timezone
only affect text representaion of dates, while asyncpg uses binary I/O in which Postgres always returns as a UTC timestamp fortimestamp with time zone
. So, any timezone manipulation would have to be done on the client side, but that is also problematic, because supportingPGTZ
would require a dependency on a timezone-capable library likedateutil
, which I’m reluctant to add just for this.The good news is that asyncpg is flexible enough to let you implement this yourself. Here’s a complete example using
dateutil
:No matter how minor it is, bug is bug.
I also tested with psycopg3 and it does recognize the PGTZ environment variable.