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
Views: Raw Message | Whole Thread | Download mbox | Resend email
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

Browse pgsql-novice by date

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