pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Bruno Wolff III <bruno@wolff.to>
To: Sam Adams <samadams@myfastmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Java and Currval
Date: Mon, 2 May 2005 12:41:11 -0500
Message-ID: <20050502174111.GA27823@wolff.to> (raw)
In-Reply-To: <1115051412.14477.233176976@webmail.messagingengine.com>
References: <1115051412.14477.233176976@webmail.messagingengine.com>

On Mon, May 02, 2005 at 17:30:12 +0100,
  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? 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.



view thread (4+ messages)

Message-ID: <20050502174111.GA27823@wolff.to>
Permalink:  ../20050502174111.GA27823@wolff.to/
Also on:    postgresql.org/message-id/20050502174111.GA27823@wolff.to

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: bruno@wolff.to, samadams@myfastmail.com
  Subject: Re: Java and Currval
  In-Reply-To: <20050502174111.GA27823@wolff.to>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox