Re: simple test code - Mailing list pgsql-novice

From Vibhor Kumar
Subject Re: simple test code
Date
Msg-id 6369AD15-3FD9-4C72-AB47-D39C19C2D51A@enterprisedb.com
Whole thread Raw
In response to simple test code  (java4dev <java4dev@gmail.com>)
Responses Re: simple test code
List 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

pgsql-novice by date:

Previous
From: Tom Lane
Date:
Subject: Re: exception problem
Next
From: java4dev
Date:
Subject: Re: exception problem