PostgreSQL alter type timestamp without time zone -> with time zone

前端 未结 2 1979
春和景丽
春和景丽 2021-02-01 00:37

The question is short: if I already have data in a column type timestamp without time zone, if I set the type to timestamp with time zone, what does postgresql do with this data

2条回答
  •  生来不讨喜
    2021-02-01 01:04

    It is better to specify the time zone explicitly. Say, if your timestamp are supposed to be in UTC (but without timezone), you should be wary of the fact that the timezone of the client or server might be messing everything here. Instead write:

    ALTER TABLE a ALTER COLUMN t TYPE TIMESTAMP WITH TIME ZONE USING t AT TIME ZONE 'UTC'
    

提交回复
热议问题