PostgreSQL中的dateadd函数的实现

今天在PostgreSQL数据库中取数,涉及到时间类型字段的加减法需求,发现不支持time_add函数。

绕了一大圈发现,实现方法非常简单……下面看例子

select [时间字段] +interval '2 year' from [table]

select [时间字段] + '5 min' from [table]

 

类似地,写成下面这些样子也都可以实现

select now() + interval '2 years';

select now() + interval '2 year';

select now() + interval '2 y';

select now() + interval '2 Y';

select now() + interval '2Y';

select now() + interval '1 month';

select now() - interval '3 week';

select now() + '10 min';

 

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章