Re: simple test code - Mailing list pgsql-novice

From Tom Lane
Subject Re: simple test code
Date
Msg-id 3247.1298396557@sss.pgh.pa.us
Whole thread Raw
In response to simple test code  (java4dev <java4dev@gmail.com>)
List pgsql-novice
java4dev <java4dev@gmail.com> writes:
> I have opened a SQL console from the pgAdmin tool and tried to run the
> following

> DECLARE
>  time1 TIMESTAMP (3);
>  time2 TIMESTAMP(3);
>  diff INTERVAL;
> BEGIN
>  time1 := now();
>  diff := INTERVAL '30' second;
>  time2 := time1 + diff;
>  SELECT time1, time2;
> END;

> I guess I am doing something wrong but what?

It looks like you're trying to run pl/pgsql code directly as SQL.
Postgres draws a distinction between those things, much more sharply
than Oracle does.  You need to create a function to run pl/pgsql
code in.  See the examples in the pl/pgsql part of the manual.

(If you're using PG 9.0, you only need a DO block, so the notational
overhead for a throwaway piece of code is a lot less ... but it's
still a distinct environment.)

            regards, tom lane

pgsql-novice by date:

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