Re: error code with psql - Mailing list pgsql-general

From Bruce Momjian
Subject Re: error code with psql
Date
Msg-id 200405060313.i463DFx14672@candle.pha.pa.us
Whole thread Raw
In response to error code with psql  (Tatsuo Ishii <t-ishii@sra.co.jp>)
List pgsql-general
Tatsuo Ishii wrote:
> Hi,
>
> Does anybody know how I can get error codes using psql? I know that I
> could get error codes from server log or using libpq function.  I just
> could not figure out a way to display them in psql.

Sure.  With psql, you need to set the VERBOSITY setting for psql to
access those error codes:

    test=> CREATE TABLE test (x int UNIQUE);
    NOTICE:  CREATE TABLE / UNIQUE will create implicit index "test_x_key"
    for table "test"
    CREATE TABLE

    test=> INSERT INTO test VALUES (1);
    INSERT 17225 1
    test=> INSERT INTO test VALUES (1);
    ERROR:    duplicate key violates unique constraint "test_x_key"

    test=> \set VERBOSITY 'verbose'
    test=> INSERT INTO test VALUES (1);
-->    ERROR:    23505: duplicate key violates unique constraint "test_x_key"
    LOCATION:  _bt_check_unique, nbtinsert.c:255

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 359-1001
  +  If your life is a hard drive,     |  13 Roberts Road
  +  Christ can be your backup.        |  Newtown Square, Pennsylvania 19073

pgsql-general by date:

Previous
From: Tatsuo Ishii
Date:
Subject: Re: error code with psql
Next
From: "Ed L."
Date:
Subject: select for update & lock contention