Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 5CE74116AE5C for ; Tue, 3 Jan 2012 16:54:46 -0400 (AST) Received: from sam.nabble.com ([216.139.236.26]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RiBNa-0003k4-RH for pgsql-sql@postgresql.org; Tue, 03 Jan 2012 20:54:46 +0000 Received: from [192.168.236.26] (helo=sam.nabble.com) by sam.nabble.com with esmtp (Exim 4.72) (envelope-from ) id 1RiBNO-0006xr-Eb for pgsql-sql@postgresql.org; Tue, 03 Jan 2012 12:54:30 -0800 Date: Tue, 3 Jan 2012 12:54:30 -0800 (PST) From: rverghese To: pgsql-sql@postgresql.org Message-ID: <1325624070446-5117916.post@n5.nabble.com> Subject: ignore unique violation OR check row exists MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: -0.1 (/) X-Archive-Number: 201201/11 X-Sequence-Number: 36182 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.