pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Michael Fuhr <mike@fuhr.org>
To: Sam Adams <samadams@myfastmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: Java and Currval
Date: Mon, 2 May 2005 10:46:39 -0600
Message-ID: <20050502164639.GA51265@winnie.fuhr.org> (raw)
In-Reply-To: <1115051412.14477.233176976@webmail.messagingengine.com>
References: <1115051412.14477.233176976@webmail.messagingengine.com>

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/



view thread (4+ messages)  latest in thread

Message-ID: <20050502164639.GA51265@winnie.fuhr.org>
Permalink:  ../20050502164639.GA51265@winnie.fuhr.org/
Also on:    postgresql.org/message-id/20050502164639.GA51265@winnie.fuhr.org

 · 

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: mike@fuhr.org, samadams@myfastmail.com
  Subject: Re: Java and Currval
  In-Reply-To: <20050502164639.GA51265@winnie.fuhr.org>

* 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