ignore unique violation OR check row exists

From: rverghese <riyav(at)hotmail(dot)com>
To: pgsql-sql(at)postgresql(dot)org
Subject: ignore unique violation OR check row exists
Date: 2012-01-03 20:54:30
Message-ID: 1325624070446-5117916.post@n5.nabble.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I want to insert a bunch of records and not do anything if the record already
exists. So the 2 options I considered are 1) check if row exists or insert
and 2) ignore the unique violation on insert if row exists.
Any opinions on whether it is faster to INSERT and then catch the UNIQUE
VIOLATION exception and ignore it in plpgsql versus check if row exists and
INSERT if it doesn't.
I can't seem to ignore the UNIQUE VIOLATION exception via php, since it is a
plpgsql command, so if I have to do the check and insert, alternatively i
have a function that tries to insert and then ignores the violation. I was
wondering if one way was better than the other.
Thanks

--
View this message in context: http://postgresql.1045698.n5.nabble.com/ignore-unique-violation-OR-check-row-exists-tp5117916p5117916.html
Sent from the PostgreSQL - sql mailing list archive at Nabble.com.

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Misa Simic 2012-01-03 21:53:53 Re: ignore unique violation OR check row exists
Previous Message Jasen Betts 2012-01-03 19:17:33 Re: lo_import