Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I get the current timezone name in Postgres 9.3?

I want to get the current timezone name. What I already achieved is to get the utc_offset / the timezone abbreviation via:

SELECT * FROM pg_timezone_names WHERE abbrev = current_setting('TIMEZONE') 

This gives me all Continent / Capital combinations for this timezone but not the exact timezone. For example I get:

Europe/Amsterdam Europe/Berlin 

The server is in Berlin and I want to get the timezone name of the server.

The problem I have with CET that it is always UTC+01:00 and does not account for DST iirc.

like image 902
Deutro Avatar asked Jan 29 '15 14:01

Deutro


People also ask

What is the timezone of Postgres?

PostgreSQL assumes your local time zone for any type containing only date or time. All timezone-aware dates and times are stored internally in UTC . They are converted to local time in the zone specified by the TimeZone configuration parameter before being displayed to the client.

Does Postgres timestamp have timezone?

Introduction to PostgreSQL timestamp The timestamp datatype allows you to store both date and time. However, it does not have any time zone data. It means that when you change the timezone of your database server, the timestamp value stored in the database will not change automatically.

Which one of these will the current date and time in PostgreSQL?

Introduction to PostgreSQL NOW() function Note that the NOW() function returns current date and time based on the database server's time zone setting.


1 Answers

I don't think this is possible using PostgreSQL alone in the most general case. When you install PostgreSQL, you pick a time zone. I'm pretty sure the default is to use the operating system's timezone. That will usually be reflected in postgresql.conf as the value of the parameter "timezone". But the value ends up as "localtime". You can see this setting with the SQL statement.

show timezone; 

But if you change the timezone in postgresql.conf to something like "Europe/Berlin", then show timezone; will return that value instead of "localtime".

So I think your solution will involve setting "timezone" in postgresql.conf to an explicit value rather than the default "localtime".

like image 142
Mike Sherrill 'Cat Recall' Avatar answered Sep 17 '22 18:09

Mike Sherrill 'Cat Recall'