Re: Java and Currval

From: Bruno Wolff III <bruno(at)wolff(dot)to>
To: Sam Adams <samadams(at)myfastmail(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Java and Currval
Date: 2005-05-02 17:41:11
Message-ID: 20050502174111.GA27823@wolff.to
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Mon, May 02, 2005 at 17:30:12 +0100,
Sam Adams <samadams(at)myfastmail(dot)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? Thanks.

I don't know what JAVA brings to the mix, but the argument to currval
is a string. Before version 8 you would do something like:
SELECT currval('taddress_addressid_seq')
This string isn't guaranteed to work, but would normally be the correct
one. In 8.0 there is a function that will return the sequence name.
Note that you must have also done a nextval or setval call on that
sequence in the current session or the value is undefined and trying to
access it will result in an error.

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Joel Fradkin 2005-05-02 17:49:29 odd error
Previous Message Volkan YAZICI 2005-05-02 16:49:12 Re: Java and Currval