Re: Java and Currval - Mailing list pgsql-sql

From Volkan YAZICI
Subject Re: Java and Currval
Date
Msg-id 7104a737050502094915b74816@mail.gmail.com
Whole thread Raw
In response to Java and Currval  ("Sam Adams" <samadams@myfastmail.com>)
List pgsql-sql
Hi,

On 5/2/05, Sam Adams <samadams@myfastmail.com> wrote:
> I'm having trouble getting the currval function to work from a Java
> program (or from Postgres at all). I want to get the value of addressid
> in the table taddress. The best I seem to be able to come up with is
> 'SELECT currval(taddress.addressid)'. However this gives me the error
> 'ERROR:  relation "1" does not exist' or whatever the number should be.
> I've tried lots of variations but can't seem to work it out. What am I
> doing wrong?

You should use the sequence as parameter to currval(), like:

=> \d products
Table "public.products"
-[ RECORD 1 ]----------------------------------------------------------
Column    | proid
Type      | integer
Modifiers | not null default nextval('public.products_proid_seq'::text)
=> SELECT currval(products.proid);
ERROR:  relation "1" does not exist
=> SELECT currval('public.products_proid_seq'::text);
nextval
---------     7
(1 row)

Regards.


pgsql-sql by date:

Previous
From: Michael Fuhr
Date:
Subject: Re: Java and Currval
Next
From: Bruno Wolff III
Date:
Subject: Re: Java and Currval