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 |1 Answer
Reset to default 0If 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.
本文标签:
版权声明:本文标题:postgresql - How to get current_timestamp in database timezone and not the session timezone in postgres - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1740148823a2232278.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
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:46timestamp 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