PostgreSQL 中的 DATEADD 等价物

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/27080505/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:50:12  来源:igfitidea点击:

DATEADD equivalent in PostgreSQL

postgresqlequivalentdateadd

提问by Hink

Is there an equivalent to this T-SQL command in PostgreSQL?

PostgreSQL 中是否有与此 T-SQL 命令等效的命令?

select dateadd(hh,duration_in_hours,start_date) as end_date

I have found only interval keyword with subsequent string, but this terrible construction returns syntax error:

我只找到了带有后续字符串的间隔关键字,但是这个可怕的构造返回语法错误:

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

It allows only string constant after "interval " keyword. I am sure there must be some similar function in pgsql, but I cannot find it.

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

回答by jpw

You can do it like this:

你可以这样做:

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

See this sample SQL Fiddle

请参阅此示例 SQL 小提琴