Re: getting details about integrity constraint violation

From: "Greg Sabino Mullane" <greg(at)turnstep(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Cc: twanger(at)bluetwanger(dot)de
Subject: Re: getting details about integrity constraint violation
Date: 2005-06-14 03:39:47
Message-ID: 873b36387522e9a014ec0c75cbb63338@biglumber.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)turnstep(dot)com
PGP Key: 0x14964AC8 200506121520
http://biglumber.com/x/web?pk=2529DF6AB8F79407E94445B4BC9B906714964AC8
-----BEGIN PGP SIGNATURE-----

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message alessio 2005-06-14 05:38:53 Spam Re: read it immediately
Previous Message postgres 2005-06-13 21:52:51 Re: Aggregate Functions Template