Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Postgresql 在PostgresSQL中将整数转换为时间戳_Postgresql_Timestamp_Integer - Fatal编程技术网

Postgresql 在PostgresSQL中将整数转换为时间戳

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

我正在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 
ELSE 0 END AS date
但这是一场灾难……

您可以使用:

CASE WHEN year > 0 THEN
   CAST (format('%s-08-31', year) AS timestamp)
END

这将为非正值年份提供空值。

时间戳不能为0。你喜欢空值还是-无穷大?