Re: How do I specify intervals in functions?

From: Michael Glaesemann <michael(dot)glaesemann(at)myyearbook(dot)com>
To: "Rob Richardson" <Rob(dot)Richardson(at)rad-con(dot)com>
Cc: "pgsql-general(at)postgresql(dot)org General" <pgsql-general(at)postgresql(dot)org>
Subject: Re: How do I specify intervals in functions?
Date: 2008-07-31 12:47:55
Message-ID: 76337B52-3575-4574-9518-7A95DDF07CC4@myyearbook.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


On 2008-07-31, at 8:36 AM, Rob Richardson wrote:

> declare
> ThreeHours interval;
> begin
> ThreeHours = interval '3 hours'; -- throws a syntax error
> ThreeHours = '3 hours'::interval; -- also throws a syntax error
> end;
>
> So how do I specify an interval in a function?

Works for me:

CREATE FUNCTION
three_hours()
RETURNS interval
STABLE
STRICT
LANGUAGE plpgsql AS $body$
declare
ThreeHours interval;
begin
ThreeHours = interval '3 hours'; -- throws a syntax error
ThreeHours = '3 hours'::interval; -- also throws a syntax error
RETURN ThreeHours;
end
$body$;
CREATE FUNCTION

test=# select three_hours();
three_hours
-------------
03:00:00
(1 row)

test=# select version();
version
-----------------------------------------------------------------------------------------------------
PostgreSQL 8.2.5 on x86_64-unknown-linux-gnu, compiled by GCC gcc
(GCC) 4.1.2 (Gentoo 4.1.2 p1.0.2)
(1 row)

I can't tell as you haven't provided a complete example (always
helpful when debugging), but are you sure you're specifying the
correct language type (plpgsql in your case)?

Michael Glaesemann
michael(dot)glaesemann(at)myyearbook(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Volkan YAZICI 2008-07-31 12:51:47 Re: How do I specify intervals in functions?
Previous Message Rob Richardson 2008-07-31 12:36:37 How do I specify intervals in functions?