X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id D0DF9537E0 for ; Mon, 2 May 2005 13:46:50 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 29423-09 for ; Mon, 2 May 2005 16:46:45 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 5388A52953 for ; Mon, 2 May 2005 13:46:44 -0300 (ADT) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id j42Gkem4006627 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 2 May 2005 10:46:42 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.3/8.13.3) with ESMTP id j42Gkd1Q051309; Mon, 2 May 2005 10:46:39 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.3/8.13.3/Submit) id j42GkdUX051308; Mon, 2 May 2005 10:46:39 -0600 (MDT) (envelope-from mfuhr) Date: Mon, 2 May 2005 10:46:39 -0600 From: Michael Fuhr To: Sam Adams Cc: pgsql-sql@postgresql.org Subject: Re: Java and Currval Message-ID: <20050502164639.GA51265@winnie.fuhr.org> References: <1115051412.14477.233176976@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1115051412.14477.233176976@webmail.messagingengine.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.005 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/17 X-Sequence-Number: 21330 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/