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

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 (view raw or flat)
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

pgsql-novice by date

Next:From: Vibhor KumarDate: 2011-02-22 17:45:50
Subject: Re: simple test code
Previous:From: java4devDate: 2011-02-22 17:34:41
Subject: exception problem

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