From: | Michael Fuhr <mike(at)fuhr(dot)org> |
---|---|
To: | Ron St-Pierre <rstpierre(at)syscor(dot)com> |
Cc: | pgsql-general <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: INTERVAL in a function |
Date: | 2004-11-09 01:00:32 |
Message-ID: | 20041109010032.GA71358@winnie.fuhr.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
On Mon, Nov 08, 2004 at 04:15:34PM -0800, Ron St-Pierre wrote:
> SELECT INTO exptime current_timestamp + INTERVAL ''intval'';
You're using the literal value 'intval' instead of its value, thus
the syntax error. You can simplify the statement to this:
exptime := current_timestamp + intval;
But I think the entire function can be shortened to:
CREATE OR REPLACE FUNCTION getUnitTimeLength(int) RETURNS TIMESTAMP AS '
SELECT CURRENT_TIMESTAMP::timestamp + unitTimeLength
FROM customer.groups
WHERE groupsID = $1
' LANGUAGE sql;
You don't need to check for NULL because the result of the addition
will already be NULL if either operand is NULL. Casting CURRENT_TIMESTAMP
is necessary to avoid a "return type mismatch" error.
--
Michael Fuhr
http://www.fuhr.org/~mfuhr/
From | Date | Subject | |
---|---|---|---|
Next Message | Kenji Morishige | 2004-11-09 01:00:49 | Newbie Question, how to grant permissions on all tables in schema/db |
Previous Message | Tom Lane | 2004-11-09 00:58:44 | Re: Backend disconnect problems |