Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id A2415B5DC60 for ; Mon, 5 Sep 2011 07:29:37 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 38973-06 for ; Mon, 5 Sep 2011 10:29:31 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from softlayer.compulab.co.il (50.23.254.54-static.reverse.softlayer.com [50.23.254.54]) by mail.postgresql.org (Postfix) with ESMTP id 5E641B5DC5F for ; Mon, 5 Sep 2011 07:29:31 -0300 (ADT) Received: from [62.90.235.247] (port=36449 helo=zimbra-mta.compulab.co.il) by softlayer.compulab.co.il with esmtp (Exim 4.69) (envelope-from ) id 1R0WQk-0003kj-3w for pgsql-general@postgresql.org; Mon, 05 Sep 2011 13:29:30 +0300 Received: from localhost (localhost.localdomain [127.0.0.1]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id 723877E9506 for ; Mon, 5 Sep 2011 13:29:27 +0300 (IDT) X-Virus-Scanned: amavisd-new at compulab.co.il Received: from zimbra-mta.compulab.co.il ([127.0.0.1]) by localhost (zimbra-mta.compulab.co.il [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id BK78m6-Vkqlq for ; Mon, 5 Sep 2011 13:29:27 +0300 (IDT) Received: from [10.1.1.27] (sim-pc.compulab.local [10.1.1.27]) by zimbra-mta.compulab.co.il (Postfix) with ESMTP id 3B15A7E94FC for ; Mon, 5 Sep 2011 13:29:27 +0300 (IDT) Message-ID: <4E64A444.5070604@compulab.co.il> Date: Mon, 05 Sep 2011 13:28:20 +0300 From: Sim Zacks User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.20) Gecko/20110805 Lightning/1.0b2 Thunderbird/3.1.12 MIME-Version: 1.0 To: pgsql-general@postgresql.org Subject: Re: conditional insert References: In-Reply-To: Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - softlayer.compulab.co.il X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - compulab.co.il X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.812 tagged_above=-5 required=5 tests=BAYES_00=-1.9, HTML_MESSAGE=0.001, KHOP_DYNAMIC=0.73, MIME_HTML_ONLY=0.723, TO_NO_BRKTS_HTML_ONLY=1.258 X-Spam-Level: X-Archive-Number: 201109/100 X-Sequence-Number: 179458 On 09/05/2011 12:38 PM, Pau Marc Muñoz Torres wrote:
Hi follk

 i trying  to performe a  conditional insert into a table, indeed, what i'm trying to do is not insert a record into the table if that record exist

googleling i found something like

 insert into XX values (1,2,3) where not exist (select ....);

but i'm having and error near where...

anyone knows how do i can perfome this insert?

thanks

p

You can either do an Insert(...) select... from...where...

or you can add a rule to the table that checks if the key exists and if so, do an update or nothing instead.