Re: handling duplicate row exception - Mailing list pgsql-sql

From Filip Rembiałkowski
Subject Re: handling duplicate row exception
Date
Msg-id CAP_rwwkHqUHmK3rYL3hvH2=R6MPbapqyuTtOi923GnULjRfZCw@mail.gmail.com
Whole thread Raw
In response to handling duplicate row exception  (Amar Dhole <adhole@tibco.com>)
Responses Re: handling duplicate row exception
List pgsql-sql
Hi<br /><br />There is no IGNORE_DUP_KEY equivalent in PostgreSQL.<br /><br />If you are 100% sure that you want to
ignoreunique key violations, you can wrap your INSERT code in PL/PgSQL block and handle the exception yourself.<br
/><br/>I mean:<br /><br />DO $$<br />BEGIN<br /> INSERT INTO foo (bar,baz) SELECT 42, 666;<br /> EXCEPTION WHEN
unique_violationTHEN RAISE NOTICE 'row skipped';<br />END;<br />$$ <br /><br /><br />BTW - which version of PostgreSQL
areyou using?<br /><br />Filip<br /><br /><br /><br /><div class="gmail_quote">2011/9/21 Amar Dhole <span
dir="ltr"><<ahref="mailto:adhole@tibco.com">adhole@tibco.com</a>></span><br /><blockquote class="gmail_quote"
style="margin:00 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;"> Hi All,<br /><br /> I have a requirement where
myapplication tries to enter the duplicate row in table using batchexceute code. And batch exception is thrown we
checkederror code and skip it but after this exception all my next update/insert gets error out with following
exception<br/><br /> "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
endof transaction block.:<br /><br /><br />  Is there any way to proceed ahead like in sql server we have options while
creatingtable IGNORE_DUP_KEY = ON if this is set warning is generated instead of Exception so the other insert/update
canproceed ahead.<br /><font color="#888888"><br /><br /><br /> --<br /> Sent via pgsql-sql mailing list (<a
href="mailto:pgsql-sql@postgresql.org">pgsql-sql@postgresql.org</a>)<br/> To make changes to your subscription:<br /><a
href="http://www.postgresql.org/mailpref/pgsql-sql"target="_blank">http://www.postgresql.org/mailpref/pgsql-sql</a><br
/></font></blockquote></div><br/> 

pgsql-sql by date:

Previous
From: Amar Dhole
Date:
Subject: handling duplicate row exception
Next
From: Brian Sherwood
Date:
Subject: Re: select xpath ...