PostgreSQL中的DATEADD等效项 [英] DATEADD equivalent in PostgreSQL
本文介绍了PostgreSQL中的DATEADD等效项的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
PostgreSQL中是否有与此T-SQL命令等效的内容?
Is there an equivalent to this T-SQL command in PostgreSQL?
select dateadd(hh,duration_in_hours,start_date) as end_date
我只找到带有后续字符串的interval关键字,但是这种可怕的构造返回语法错误:
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'
interval关键字后仅允许字符串常量。我确定pgsql中肯定有一些类似的函数,但是我找不到它。
It allows only string constant after "interval " keyword. I am sure there must be some similar function in pgsql, but I cannot find it.
推荐答案
您可以这样做:
select start_date + (duration_in_hours * interval '1 hour') from your_table
请参阅此示例SQL Fiddle
这篇关于PostgreSQL中的DATEADD等效项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文