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 D33E95331D for ; Mon, 2 May 2005 14:21:20 -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 60492-02 for ; Mon, 2 May 2005 17:21:15 +0000 (GMT) Received: from wolff.to (wolff.to [66.93.197.194]) by svr1.postgresql.org (Postfix) with SMTP id 1313C52A2D for ; Mon, 2 May 2005 14:21:14 -0300 (ADT) Received: (qmail 29548 invoked by uid 500); 2 May 2005 17:41:11 -0000 Date: Mon, 2 May 2005 12:41:11 -0500 From: Bruno Wolff III To: Sam Adams Cc: pgsql-sql@postgresql.org Subject: Re: Java and Currval Message-ID: <20050502174111.GA27823@wolff.to> Mail-Followup-To: Bruno Wolff III , Sam Adams , pgsql-sql@postgresql.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> User-Agent: Mutt/1.5.6i X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.01 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/19 X-Sequence-Number: 21332 On Mon, May 02, 2005 at 17:30:12 +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)'. 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.