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';

 

 

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