Re: UNIQUE_VIOLATION exception, finding out which index would have been violated

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: Petri Simolin <petrisimolin(at)petrisimolin(dot)com>
Cc: Postgres General <pgsql-general(at)postgresql(dot)org>
Subject: Re: UNIQUE_VIOLATION exception, finding out which index would have been violated
Date: 2007-09-25 07:43:28
Message-ID: 20070925074328.GA60682@winnie.fuhr.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Tue, Sep 25, 2007 at 04:55:37AM -0200, Petri Simolin wrote:
> I have created a function which inserts a row in a table which has 2 unique
> indexes on two different columns.
>
> I am wondering, if there is a way in case of UNIQUE_VIOLATION exception to
> find out which index would have been violated?

In PL/pgSQL you could extract the constraint name from SQLERRM,
which should be a string like 'duplicate key violates unique
constraint "foo_id1_key"'.

--
Michael Fuhr

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Devrim GÜNDÜZ 2007-09-25 08:07:37 Re: PgpoolAdmin installation
Previous Message Ashish Karalkar 2007-09-25 07:27:29 PgpoolAdmin installation