Re: simple test code

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: java4dev <java4dev(at)gmail(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: simple test code
Date: 2011-02-22 17:42:37
Message-ID: 3247.1298396557@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

java4dev <java4dev(at)gmail(dot)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

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Vibhor Kumar 2011-02-22 17:45:50 Re: simple test code
Previous Message java4dev 2011-02-22 17:34:41 exception problem