| From: | Laurent <lduperval(at)gmail(dot)com> |
|---|---|
| To: | pgsql-novice(at)postgresql(dot)org |
| Subject: | Declaring timestamp variables in function |
| Date: | 2011-03-10 21:35:15 |
| Message-ID: | f6284a76-53f6-4301-bd1a-96837accfb35@y36g2000pra.googlegroups.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-novice |
Hi,
I'm trying to create a function that updates fields according to the
current date. One of the fields needs to be a numeric UTC value.
So, I'm trying something like this:
-- This rounds a timestamp to the the nearest 30 minute mark
CREATE OR REPLACE FUNCTION round_time(TIMESTAMP WITH TIME ZONE)
RETURNS TIMESTAMP WITH TIME ZONE AS $$
SELECT date_trunc('hour', $1) + INTERVAL '30 min' *
ROUND(date_part('minute', $1) / 30.0)
$$ LANGUAGE SQL;
CREATE or replace FUNCTION updateDates() RETURNS void AS $$
declare
currentDate timestamp(3);
BEGIN
currentDate = := round_time(current_date);
...
-- here I update my date
END;
$$ LANGUAGE SQL;
The problem is that my currentDate declaration always generates an
error:
********** Error **********
ERROR: syntax error at or near "timestamp"
SQL state: 42601
Character: 301
I thought this was legal syntax (with 8.4) but evidently, I'm wrong.
My questions is: where?
Thanks,
L
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tom Lane | 2011-03-10 23:27:26 | Re: Declaring timestamp variables in function |
| Previous Message | Francisco Leovey | 2011-03-10 18:02:37 | psql in postgres 9.0.3 not accepting password |