我在PostgreSQL中有以下SQL Server脚本。
SQL Server脚本:
convert(datetime,convert(varchar,JoinTiming,108))
我的尝试:
to_timestamp(to_char(JoinTiming,'HH24:MI:SS'))
错误:
ERROR: function to_timestamp(text) does not exist
答案 0 :(得分:1)
PostgreSQL有一个"时间"数据类型。
select current_timestamp::time(0) -- or
select cast(current_timestamp as time(0))
now time without time zone -- 06:51:58
在PostgreSQL中,您无法将时间投入到时间戳中。
时间戳包含日期和时间 - PostgreSQL应该使用哪个日期?没有办法知道。所以PostgreSQL根本就不允许这种演员。
您可以添加类型"时间"日期和时间戳。所以像这样的表达式会起作用。
select date '2001-01-01' + '13:43'::time(0)
select '2001-01-01'::date + '13:43'::time(0)
select (current_timestamp + '13:43'::time(0))::timestamp(0)
此外,标准SQL CAST()的工作方式与您相同。
select cast(current_timestamp as time(0))