Re: Java and Currval - Mailing list pgsql-sql

From Michael Fuhr
Subject Re: Java and Currval
Date
Msg-id 20050502164639.GA51265@winnie.fuhr.org
Whole thread Raw
In response to Java and Currval  ("Sam Adams" <samadams@myfastmail.com>)
List pgsql-sql
On Mon, May 02, 2005 at 05:30:12PM +0100, Sam Adams 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)'.

The argument to currval() is a quoted sequence name, so you probably
need something like this:

SELECT currval('taddress_addressid_seq');

In PostgreSQL 8.0 you can use pg_get_serial_sequence() to get the
sequence name from the table and column names:

SELECT currval(pg_get_serial_sequence('taddress', 'addressid'));

-- 
Michael Fuhr
http://www.fuhr.org/~mfuhr/


pgsql-sql by date:

Previous
From: "Sam Adams"
Date:
Subject: Java and Currval
Next
From: Volkan YAZICI
Date:
Subject: Re: Java and Currval