pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Craig Ringer <craig@postnewspapers.com.au>
To: Marcin Krawczyk <jankes.mk@gmail.com>
Cc: pgsql-sql@postgresql.org
Subject: Re: error codes
Date: Thu, 17 Apr 2008 18:43:16 +0800
Message-ID: <480729C4.7040802@postnewspapers.com.au> (raw)
In-Reply-To: <95f6bf9b0804170123w271df42er3b377c1b9a3f0244@mail.gmail.com>
References: <95f6bf9b0804170123w271df42er3b377c1b9a3f0244@mail.gmail.com>

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



view thread (3+ messages)  latest in thread

Message-ID: <480729C4.7040802@postnewspapers.com.au>
Permalink:  ../480729C4.7040802@postnewspapers.com.au/
Also on:    postgresql.org/message-id/480729C4.7040802@postnewspapers.com.au

 · 

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: craig@postnewspapers.com.au, jankes.mk@gmail.com
  Subject: Re: error codes
  In-Reply-To: <480729C4.7040802@postnewspapers.com.au>

* 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