pg.ddx.io  pgsql-admin@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Scott Marlowe <scott.marlowe@gmail.com>
To: Dinesh <dbhandary@mongonet.net>
Cc: pgsql-admin@postgresql.org
Subject: Re: error handling unique key constraint in pgsql
Date: Tue, 10 Jun 2008 13:09:52 -0600
Message-ID: <dcc563d10806101209x4edfd77dl28bf514a0742d845@mail.gmail.com> (raw)
In-Reply-To: <484EB14B.4010003@mongonet.net>
References: <484EB14B.4010003@mongonet.net>

On Tue, Jun 10, 2008 at 10:52 AM, Dinesh <dbhandary@mongonet.net> wrote:
> Hi All,
>
> I was wondering if there is an easy way to handle unique key constraint in
> pgsql. Right now my entire transaction aborts if it tries to insert
> duplicate keys, but I would like to handle this
> scenario in such a way that the transaction will not break.
>
> Please let me know if you have done something like this. I greatly
> appreciate your help.

There are a couple of approaches:

process the inserts in a pl/pgsql function  and use the exception
handling in there to catch them.

Use savepoints.

Both of these use the same underlying mechanisms, and both tend to be
expensive in terms of overhead.



view thread (5+ messages)  latest in thread

Message-ID: <dcc563d10806101209x4edfd77dl28bf514a0742d845@mail.gmail.com>
Permalink:  ../dcc563d10806101209x4edfd77dl28bf514a0742d845@mail.gmail.com/
Also on:    postgresql.org/message-id/dcc563d10806101209x4edfd77dl28bf514a0742d845@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-admin@postgresql.org
  Cc: scott.marlowe@gmail.com, dbhandary@mongonet.net
  Subject: Re: error handling unique key constraint in pgsql
  In-Reply-To: <dcc563d10806101209x4edfd77dl28bf514a0742d845@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox