题
如果我在PL / pgSQL中有一个接收时间戳的函数,那么识别该日期是否少于12个月的最佳方法是什么?
e.g。
CREATE FUNCTION do_something(foo timestamp) ....
-- IF foo is less than 12 months in the past THEN
-- do something
-- END IF;
END;
解决方案
了解 PostgreSQL doc:日期类型的时间间隔。使用类似的东西:
where foo < CURRENT_TIMESTAMP - interval '12 months'
其他提示
或等价地:年龄(foo)<!> lt;间隔'12个月'
不隶属于 StackOverflow