Skip site navigation (1) Skip section navigation (2)

Re: simple test code

From: Vibhor Kumar <vibhor(dot)kumar(at)enterprisedb(dot)com>
To: java4dev <java4dev(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: simple test code
Date: 2011-02-22 17:45:50
Message-ID: 6369AD15-3FD9-4C72-AB47-D39C19C2D51A@enterprisedb.com (view raw or flat)
Thread:
Lists: pgsql-novice
> 
> DECLARE
> time1 TIMESTAMP (3);
> time2 TIMESTAMP(3);
> diff INTERVAL;
> BEGIN
> time1 := now();
> diff := INTERVAL '30' second;
> time2 := time1 + diff;
> SELECT time1, time2;
> END;
> 
> but I get an error that I cannot interpret
> 
> ERROR:  syntax error at or near "TIMESTAMP"
> LINE 3:  time1 TIMESTAMP (3);
>               ^
> 
> ********** Error **********
> 
> ERROR: syntax error at or near "TIMESTAMP"
> SQL state: 42601
> Character: 17
> 
> I also tryed to add a label in the beginning
> 
> <<test>>
> DECLARE
> time1 TIMESTAMP (3);
> time2 TIMESTAMP(3);
> diff INTERVAL;
> BEGIN
> time1 := now();
> diff := INTERVAL '30' second;
> time2 := time1 + diff;
> SELECT time1, time2;
> END;
> 
> but then I get 
> 
> ERROR:  syntax error at or near "<<"
> LINE 1: <<test>>
>        ^
> 
> 
> ********** Error **********
> 
> ERROR: syntax error at or near "<<"
> SQL state: 42601
> Character: 1
> 

This kind of anonymous blocks are not supported in PostgreSQL.
If you are using PG 9.0 then you can try following:
do $$
DECLARE
time1 TIMESTAMP (3);
time2 TIMESTAMP(3);
diff INTERVAL;
BEGIN
time1 := now();
diff := INTERVAL '30' second;
time2 := time1 + diff;
RAISE NOTICE '% %', time1, time2;
END;$$ language plpgsql;


Thanks & Regards,
Vibhor Kumar

In response to

Responses

pgsql-novice by date

Next:From: Tom LaneDate: 2011-02-22 17:48:14
Subject: Re: exception problem
Previous:From: Tom LaneDate: 2011-02-22 17:42:37
Subject: Re: simple test code

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group