Re: How do I specify intervals in functions?

From: Volkan YAZICI <yazicivo(at)ttmail(dot)com>
To: "Rob Richardson" <Rob(dot)Richardson(at)rad-con(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: How do I specify intervals in functions?
Date: 2008-07-31 12:51:47
Message-ID: 87sktqgqsc.fsf@alamut.mobiliz.com.tr
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"Rob Richardson" <Rob(dot)Richardson(at)rad-con(dot)com> writes:
> So how do I specify an interval in a function?

Does this help?

(vy(at)[local]:5432/test) [2008-07-31 15:49:54]
# CREATE OR REPLACE FUNCTION time_cmp_with_1w_offset
(_l_ts timestamp, _r_ts timestamp)
RETURNS boolean AS $$
DECLARE
_offset interval;
BEGIN
_offset = '1 week';
RETURN (_l_ts < _r_ts - _offset);
END;
$$ LANGUAGE plpgsql;

(vy(at)[local]:5432/test) [2008-07-31 15:49:28]
# SELECT time_cmp_with_1w_offset(CAST('2008-07-10' AS timestamp),
] CAST('2008-07-31' AS timestamp));
time_cmp_with_1w_offset
-------------------------
t
(1 row)

Regards.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Kevin Field 2008-07-31 12:52:02 Re: boolean short-circuiting in plpgsql
Previous Message Michael Glaesemann 2008-07-31 12:47:55 Re: How do I specify intervals in functions?