error code with psql

Started by Tatsuo Ishiialmost 22 years ago4 messagesgeneral
Jump to latest
#1Tatsuo Ishii
t-ishii@sra.co.jp

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

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Tatsuo Ishii (#1)
Re: error code with psql

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

#3Tatsuo Ishii
t-ishii@sra.co.jp
In reply to: Tom Lane (#2)
Re: error code with psql

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

#4Bruce Momjian
bruce@momjian.us
In reply to: Tatsuo Ishii (#1)
Re: error code with psql

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