似乎将列从 更改为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)