开发者

Checking timestamps in PL/pgSQL

If I have a function in PL/pgSQL that takes in a timestamp, what is the best way to identify whether that date is less than 开发者_JS百科12 months in the past?

e.g.

CREATE FUNCTION do_something(foo timestamp) ....
    -- IF foo is less than 12 months in the past THEN
    --    do something
    -- END IF;
END;


Read about intervals on PostgreSQL doc: Date Types. Use something like:

where foo < CURRENT_TIMESTAMP - interval '12 months'


Or, equivalently: age(foo) < interval '12 months'

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜