Re: getting details about integrity constraint violation - Mailing list pgsql-sql

From Greg Sabino Mullane
Subject Re: getting details about integrity constraint violation
Date
Msg-id 873b36387522e9a014ec0c75cbb63338@biglumber.com
Whole thread Raw
In response to getting details about integrity constraint violation  (Markus Bertheau <twanger@bluetwanger.de>)
Responses Re: getting details about integrity constraint violation
List pgsql-sql
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1


Markus Bertheau asked:
> how would I find out details about for example what constraint was
> violated by an insert statement? The SQL state tells me, that a unique
> constraint was violated, but it doesn't say which one.

Simply name the table constraints yourself with a descriptive name, so you
always know exactly what is going on:

greg=# create table unitest(a int, b text);
CREATE TABLE
greg=# alter table unitest add constraint "unitest_column_a_is_not_unique" unique(a);
NOTICE:  ALTER TABLE / ADD UNIQUE will create implicit index "unitest_column_a_is_not_unique" for table "unitest"
greg=# insert into unitest (a) values (1);
INSERT 0 1
greg=# insert into unitest (a) values (1);
ERROR:  duplicate key violates unique constraint "unitest_column_a_is_not_unique"

- --
Greg Sabino Mullane greg@turnstep.com
PGP Key: 0x14964AC8 200506121520
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

iD8DBQFCrIsevJuQZxSWSsgRAh+gAJ94AsB7rZzpxT7pogC1tgbPaQJzJQCg5YkC
E9dXkQk4qP8r8zjCEucxpt0=
=NDgJ
-----END PGP SIGNATURE-----




pgsql-sql by date:

Previous
From: postgres@jal.org
Date:
Subject: Re: Aggregate Functions Template
Next
From: alessio@albourne.com
Date:
Subject: Spam Re: read it immediately