pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Amar Dhole <adhole@tibco.com>
To: Filip RembiaƂkowski <plk.zuber@gmail.com>
To: pgsql-sql@postgresql.org <pgsql-sql@postgresql.org>
Subject: Re: handling duplicate row exception
Date: Thu, 22 Sep 2011 06:11:39 +0000
Message-ID: <B056671652AA4D418763981054BCEAB40929EB@PA-MBX04.na.tibco.com> (raw)
In-Reply-To: <CAP_rwwkHqUHmK3rYL3hvH2=R6MPbapqyuTtOi923GnULjRfZCw@mail.gmail.com>
References: <j59o2m$dn1$1@dough.gmane.org>
	<1E5EC0E1-13DB-4346-B8EE-212F4DC4CCEA@yahoo.com>
	<j5a9dt$9hc$1@dough.gmane.org>
	<B056671652AA4D418763981054BCEAB408F1BF@PA-MBX04.na.tibco.com>
	<CAP_rwwkHqUHmK3rYL3hvH2=R6MPbapqyuTtOi923GnULjRfZCw@mail.gmail.com>

Hi Filip,

No not sure 100% when this can happen. This approach will not be possible as in our application we are programmatically handling these cases and going in other route to add the record with increased key.

I am using 9.0.4 version.

Thanks
Amar

________________________________
From: pgsql-sql-owner@postgresql.org [mailto:pgsql-sql-owner@postgresql.org] On Behalf Of Filip Rembialkowski
Sent: 21 September 2011 20:37
To: Amar Dhole
Cc: pgsql-sql@postgresql.org
Subject: Re: [SQL] handling duplicate row exception

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@tibco.com<mailto:adhole@tibco.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@postgresql.org<mailto:pgsql-sql@postgresql.org>)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-sql

view thread (4+ messages)  latest in thread

Message-ID: <B056671652AA4D418763981054BCEAB40929EB@PA-MBX04.na.tibco.com>
Permalink:  ../B056671652AA4D418763981054BCEAB40929EB@PA-MBX04.na.tibco.com/
Also on:    postgresql.org/message-id/B056671652AA4D418763981054BCEAB40929EB@PA-MBX04.na.tibco.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-sql@postgresql.org
  Cc: adhole@tibco.com, plk.zuber@gmail.com
  Subject: Re: handling duplicate row exception
  In-Reply-To: <B056671652AA4D418763981054BCEAB40929EB@PA-MBX04.na.tibco.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