在 PostgreSQL 中,我使用now()andcurrent_timestamp函数,我看不出有什么区别:
# SELECT now(), current_timestamp;
now | now
--------------------------------+--------------------------------
04/20/2014 19:44:27.215557 EDT | 04/20/2014 19:44:27.215557 EDT
(1 row)
Run Code Online (Sandbox Code Playgroud)
我错过了什么吗?
似乎将列从 更改为timestamp without time zone会timestamp with time zone根据语句时的当前会话时区转换现有数据alter。
请参阅此示例,每个语句后显示输出
\ncreate table tztest (col1 timestamp without time zone);\n\nset timezone = 'UTC';\ninsert into tztest (col1) values ('2023-02-01 10:10:10');\nselect col1 as t1, extract(epoch FROM col1) from tztest;\n-- \xe2\x86\x92 2023-02-01 10:10:10 1675246210\n\nset timezone = 'America/New_York';\nalter table tztest alter column col1 type timestamp with time zone;\nselect col1 as t2, extract(epoch FROM col1) from tztest;\n-- \xe2\x86\x92 2023-02-01 10:10:10-05 1675264210\n\nset timezone = 'UTC';\nselect col1 as t3, extract(epoch FROM col1) …Run Code Online (Sandbox Code Playgroud)