Received: from localhost (unknown [200.46.204.184]) by developer.postgresql.org (Postfix) with ESMTP id 25BFA2E0056 for ; Thu, 17 Apr 2008 06:44:09 -0300 (ADT) Received: from developer.postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.184]) (amavisd-maia, port 10024) with ESMTP id 32398-08 for ; Thu, 17 Apr 2008 06:43:56 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey-1.7.5 Received: from www.postnewspapers.com.au (www.postnewspapers.com.au [202.61.230.242]) by developer.postgresql.org (Postfix) with ESMTP id 5E1352E004A for ; Thu, 17 Apr 2008 06:44:01 -0300 (ADT) Received: from mail.postnewspapers.com.au (202-89-185-120.static.dsl.amnet.net.au [202.89.185.120]) by www.postnewspapers.com.au (Postfix) with ESMTP id 3A8233D5; Thu, 17 Apr 2008 17:43:53 +0800 (WST) Received: from [10.0.0.53] (wallace.localnet [10.0.0.53]) by mail.postnewspapers.com.au (Postfix) with ESMTP id 75AC31E0434; Thu, 17 Apr 2008 17:43:56 +0800 (WST) Message-ID: <480729C4.7040802@postnewspapers.com.au> Date: Thu, 17 Apr 2008 18:43:16 +0800 From: Craig Ringer User-Agent: Icedove 1.5.0.12 (X11/20070607) MIME-Version: 1.0 To: Marcin Krawczyk Cc: pgsql-sql@postgresql.org Subject: Re: error codes References: <95f6bf9b0804170123w271df42er3b377c1b9a3f0244@mail.gmail.com> In-Reply-To: <95f6bf9b0804170123w271df42er3b377c1b9a3f0244@mail.gmail.com> X-Enigmail-Version: 0.94.2.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200804/111 X-Sequence-Number: 30650 Marcin Krawczyk wrote: > Hi guys. Does anyone know the error code for '/currval of sequence * is > not yet defined in this session/' error ? Is there one at all? A quick JDBC test program shows: ERROR: currval of sequence "customer_id_seq" is not yet defined in this session (SQLState: 55000) which, looking up the error code in the docs: http://www.postgresql.org/docs/current/static/errcodes-appendix.html turns out to be: 55000 OBJECT NOT IN PREREQUISITE STATE ... which makes sense, but I wouldn't call blindingly and immediately obvious. Here's a trivial little utility for running a statement, catching an error, and reporting the error along with the Pg error code. Sorry for the horrible formatting (short lines for email). --- Put in file `JdbcTest.java' --- import java.sql.SQLException; import java.sql.CallableStatement; import java.sql.Connection; import java.sql.DriverManager; class JdbcTest { public static void main(String[] args) throws ClassNotFoundException, InterruptedException, SQLException { Class.forName("org.postgresql.Driver"); Connection c = DriverManager.getConnection("jdbc://YOUR_PARAMS_HERE"); try { CallableStatement st = c.prepareCall("SELECT currval('customer_id_seq')"); st.execute(); } catch (SQLException ex) { System.out.println( "DB error string: " + ex.getMessage() + " (SQLState: " + ex.getSQLState() + ")"); } } } ---- end ---- You'll need the PostgreSQL JDBC driver. To compile (assuming you don't use a Java IDE of some sort, but have the JDK installed) run: javac -d /out/dir JdbcTest.java and to run (all on one line): java -classpath /path/to/postgresql-8.3-603.jdbc4.jar:/out/dir JdbcTest where /out/dir is wherever you want the generated .class file to be put. -- Craig Ringer