Postgresql 在PostgresSQL中将整数转换为时间戳
我正在PostgreSQL中创建一个视图。我有一个表,其中列Postgresql 在PostgresSQL中将整数转换为时间戳,postgresql,timestamp,integer,Postgresql,Timestamp,Integer,我正在PostgreSQL中创建一个视图。我有一个表,其中列year为整数类型,并希望将其转换为带有特定月/日的新列中不带时区的时间戳,例如: year | date ----------- 1999 | 1999-08-31 0 | 0 所有年份都应进行“08-31” 目前,我有: CASE When year > 0 Then concat(year, '-08-31') AND to_timestamp(year):: timestamp without time zone
year
为整数类型,并希望将其转换为带有特定月/日的新列中不带时区的时间戳,例如:
year | date
-----------
1999 | 1999-08-31
0 | 0
所有年份都应进行“08-31”
目前,我有:
CASE When year > 0 Then concat(year, '-08-31') AND to_timestamp(year):: timestamp without time zone
ELSE 0 END AS date
但这是一场灾难……您可以使用:
CASE WHEN year > 0 THEN
CAST (format('%s-08-31', year) AS timestamp)
END
这将为非正值年份提供空值。时间戳不能为0。你喜欢空值还是-无穷大?