Received: from makus.postgresql.org (makus.postgresql.org [98.129.198.125]) by mail.postgresql.org (Postfix) with ESMTP id 9CBC6116AE5D for ; Tue, 3 Jan 2012 17:54:09 -0400 (AST) Received: from mail-iy0-f174.google.com ([209.85.210.174]) by makus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1RiCJ3-0004hl-ST for pgsql-sql@postgresql.org; Tue, 03 Jan 2012 21:54:10 +0000 Received: by iaeh11 with SMTP id h11so31468400iae.19 for ; Tue, 03 Jan 2012 13:53:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:from:date:message-id:subject:to:content-type; bh=WjL+tmBZ03J0TEagSud/BQ1wYIoWxhPqV9NbT1kgM0A=; b=nTaDoCPE7ntzKHPPA6vhs/419auCypaT23qbEN5QuVgVbj6URjv1rHr+01scYSxrX3 8M6Bi9xjyHVa1AUyXh1q9+UtA5rNJzz0tXdGuIDtq2qqXpOV/AyPDerqvAlFxXwc62ME 60qSjQAGlYzeCJYXxQQla5pZQ3hkFlUIFDuFc= Received: by 10.42.76.66 with SMTP id d2mr57030377ick.7.1325627633562; Tue, 03 Jan 2012 13:53:53 -0800 (PST) MIME-Version: 1.0 From: Misa Simic Date: Tue, 3 Jan 2012 13:53:53 -0800 Message-ID: <1640378676151393930@unknownmsgid> Subject: Re: ignore unique violation OR check row exists To: rverghese , "pgsql-sql@postgresql.org" Content-Type: text/plain; charset=UTF-8 X-Pg-Spam-Score: -1.5 (-) X-Archive-Number: 201201/12 X-Sequence-Number: 36183 If exists is better, though insert line by line and check if exists may be very slow... The best would be if you can use copy command from csv to staging table (without constraints) and then Insert to live from stage where stage constraint column not exist in live... Kind Regards, Misa Sent from my Windows Phone From: rverghese Sent: 03/01/2012 21:55 To: pgsql-sql@postgresql.org Subject: [SQL] ignore unique violation OR check row exists 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. -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql