简体   繁体   English

获取postgres以显示UTC中的所有TIMESTAMP WITH TIME ZONE列

[英]Get postgres to show all TIMESTAMP WITH TIME ZONE columns in UTC

When I do a SELECT statement that outputs a TIMESTAMP WITH TIME ZONE column, it doesn't include the time zone in the output. 当我执行输出TIMESTAMP WITH TIME ZONE列的SELECT语句时,它在输出中不包含时区。 It just outputs the date and time without the timezone, after converting it to my local timezone. 在将日期和时间转换为我的本地时区后,它只输出不带时区的日期和时间。

I have 2 questions: 我有两个问题:

  • How to get all TIMESTAMP WITH TIME ZONE columns to always display their time zones in the output, rather than the default of omitting it? 如何获取所有TIMESTAMP WITH TIME ZONE列以始终在输出中显示其时区,而不是默认省略时区?
  • How to get all TIMESTAMP WITH TIME ZONE columns to output with a default time zone of UTC ? 如何获取所有TIMESTAMP WITH TIME ZONE列以默认的UTC时区输出? I know there's ways to do this on a per-query basis, but I'd like to do it in every case with needing to modify any queries. 我知道可以根据每个查询执行此操作,但是我想在每种情况下都需要修改任何查询。 So a server setting maybe? 那么也许是服务器设置?

for one column: 一栏:

 SELECT colname AT TIME ZONE 'UTC' FROM tablename;

for all 对全部

 SET TIMEZONE TO 'UTC';

see also ALTER ... SET ... 另请参阅ALTER ... SET ...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM