Thread: error code with psql

error code with psql

From
Tatsuo Ishii
Date:
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.
--
Tatsuo Ishii

Re: error code with psql

From
Tom Lane
Date:
Tatsuo Ishii <t-ishii@sra.co.jp> writes:
> 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.

"\set VERBOSITY verbose".  Might be more than you want though...

            regards, tom lane

Re: error code with psql

From
Tatsuo Ishii
Date:
> Tatsuo Ishii <t-ishii@sra.co.jp> writes:
> > 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.
>
> "\set VERBOSITY verbose".  Might be more than you want though...

Oh, thanks.
--
Tatsuo Ishii

Re: error code with psql

From
Bruce Momjian
Date:
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