Re: handling duplicate row exception

From: Filip Rembiałkowski <plk(dot)zuber(at)gmail(dot)com>
To: Amar Dhole <adhole(at)tibco(dot)com>
Cc: "pgsql-sql(at)postgresql(dot)org" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: handling duplicate row exception
Date: 2011-09-21 15:07:29
Message-ID: CAP_rwwkHqUHmK3rYL3hvH2=R6MPbapqyuTtOi923GnULjRfZCw@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Hi

There is no IGNORE_DUP_KEY equivalent in PostgreSQL.

If you are 100% sure that you want to ignore unique key violations, you can
wrap your INSERT code in PL/PgSQL block and handle the exception yourself.

I mean:

DO $$
BEGIN
INSERT INTO foo (bar,baz) SELECT 42, 666;
EXCEPTION WHEN unique_violation THEN RAISE NOTICE 'row skipped';
END;
$$

BTW - which version of PostgreSQL are you using?

Filip

2011/9/21 Amar Dhole <adhole(at)tibco(dot)com>

> Hi All,
>
> I have a requirement where my application tries to enter the duplicate row
> in table using batchexceute code. And batch exception is thrown we checked
> error code and skip it but after this exception all my next update/insert
> gets error out with following exception
>
> "Database error. SQL state 25P02. Database specific error code (if any) was
> 0. Database error message (if any) was: org.postgresql.util.PSQLException:
> ERROR: current transaction is aborted, commands ignored until end of
> transaction block.:
>
>
> Is there any way to proceed ahead like in sql server we have options while
> creating table IGNORE_DUP_KEY = ON if this is set warning is generated
> instead of Exception so the other insert/update can proceed ahead.
>
>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message jablonov 2011-09-21 15:32:04 Re: Trigger Procedure Error: NEW used in query that is not in a rule
Previous Message Amar Dhole 2011-09-21 05:54:55 handling duplicate row exception