DATEADD equivalent in PostgreSQL [duplicate]

血红的双手。 提交于 2019-12-01 14:54:02

问题


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

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.


回答1:


You can do it like this:

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

See this sample SQL Fiddle



来源:https://stackoverflow.com/questions/27080505/dateadd-equivalent-in-postgresql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!