PostgreSQL中的DATEADD等价物

时间:2014-11-22 17:47:06

标签: postgresql equivalent dateadd

PostgreSQL中是否存在与此T-SQL命令等效的内容?

select dateadd(hh,duration_in_hours,start_date) as end_date

我发现只有带有后续字符串的interval关键字,但是这个糟糕的构造会返回语法错误:

select start_date + interval cast(duration_in_hours as varchar) || ' hours'

在“interval”关键字后只允许字符串常量。我确信在pgsql中必定有一些类似的功能,但我找不到它。

1 个答案:

答案 0 :(得分:13)

你可以这样做:

select start_date + (duration_in_hours * interval '1 hour') from your_table

请参阅此sample SQL Fiddle

相关问题