admin管理员组

文章数量:1244223

I have a column in my postgres table which stores the time at which row is inserted or modified in the database. I need to rely on current_timestamp method However it generates in session timezone and not the database timezone. I checked the documentation and could not find out any way to get the database timezone. If I have database timezone I can do current_timestamp at DBTIMEZONE if DBTIMEZONE is database timezone. Is there any way to get db time zone or to generate current_timestamp in database timezone ?

I have a column in my postgres table which stores the time at which row is inserted or modified in the database. I need to rely on current_timestamp method However it generates in session timezone and not the database timezone. I checked the documentation and could not find out any way to get the database timezone. If I have database timezone I can do current_timestamp at DBTIMEZONE if DBTIMEZONE is database timezone. Is there any way to get db time zone or to generate current_timestamp in database timezone ?

Share Improve this question asked Feb 17 at 15:09 yatharth govilyatharth govil 113 bronze badges 3
  • You appear confused. The CURRENT_TIMESTAMP "function" returns timestamptz which is an absolute time. It obviously displays in your client time-zone because that is what the client-zone is for. You can read the TimeZone from pg_settings but you probably don't want to. – Richard Huxton Commented Feb 17 at 15:46
  • 1) What is the data type for the column the 'CURRENT_TIMESTAMP` value is being stored in? 2) If it is timestamp with time zone then the value is always going to be stored as UTC. 3) How it is displayed to the end user is a client issue. – Adrian Klaver Commented Feb 17 at 16:37
  • I need to store it in timestamp without timezone – yatharth govil Commented Feb 18 at 4:50
Add a comment  | 

1 Answer 1

Reset to default 0

If you want a specific timezone you can do the following:

select current_timestamp at time zone 'America/Chicago'

Otherwise, if you definitely want to use the database timezone, use Palak's answer.

本文标签: