Declaring timestamp variables in function - Mailing list pgsql-novice

From Laurent
Subject Declaring timestamp variables in function
Date
Msg-id f6284a76-53f6-4301-bd1a-96837accfb35@y36g2000pra.googlegroups.com
Whole thread Raw
Responses Re: Declaring timestamp variables in function  (Tom Lane <tgl@sss.pgh.pa.us>)
List 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

pgsql-novice by date:

Previous
From: Francisco Leovey
Date:
Subject: psql in postgres 9.0.3 not accepting password
Next
From: Tom Lane
Date:
Subject: Re: Declaring timestamp variables in function