Postgresql 创建表字段名时间戳与时区 UTC

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/42978727/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-21 02:32:19  来源:igfitidea点击:

Postgresql Create Table Fieldname Timestamp with Time Zone UTC

postgresqltimestampcreate-table

提问by Rich_F

What is the syntax for creating a table with a field with the UTC time zone?

创建带有 UTC 时区字段的表的语法是什么?

I have for the fields:

我有以下领域:

(id INT PRIMARY KEY NOT NULL, 
 bravo timestamp without time zone DEFAULT now(),
 charlie timestamp with time zone UTC DEFAULT now()
)

This last field named charlieis not taking for some reason. I was hoping it was easy as just telling it had a time zone, then shoving UTC in there, and having the db figure out now()during input.

charlie由于某种原因,最后一个命名的字段没有被采用。我希望这很容易,因为只是告诉它有一个时区,然后将 UTC 推到那里,并now()在输入过程中找出数据库。

回答by Laurenz Albe

I think you want this:

我想你想要这个:

charlie timestamp without time zone NOT NULL
   DEFAULT (current_timestamp AT TIME ZONE 'UTC')