Received: from malur.postgresql.org ([2a02:16a8:dc51::56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fMDVB-0002Ct-Lp for pgsql-general@arkaria.postgresql.org; Fri, 25 May 2018 14:15:29 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fMDVA-0006YJ-KT for pgsql-general@arkaria.postgresql.org; Fri, 25 May 2018 14:15:28 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fMDVA-0006Y1-90 for pgsql-general@lists.postgresql.org; Fri, 25 May 2018 14:15:28 +0000 Received: from [2001:41c9:1:41d::10] (helo=srv01.teladesign.ie) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1fMDV6-0007Vo-Lb for pgsql-general@lists.postgresql.org; Fri, 25 May 2018 14:15:26 +0000 Received: from [93.107.231.214] (helo=[192.168.1.132]) by srv01.teladesign.ie with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.84_2) (envelope-from ) id 1fMDV1-0003GI-99; Fri, 25 May 2018 15:15:19 +0100 Reply-To: rod@iol.ie To: Igor Neyman , tango ward , Adrian Klaver Cc: "David G. Johnston" , "pgsql-generallists.postgresql.org" References: <0a76f762-88d8-75a7-de3c-d76094638fdd@aklaver.com> <6f46b2b5-c69a-fa85-a66b-8ff318a82aa1@aklaver.com> From: Raymond O'Donnell Message-ID: <11c14f05-ebe6-cbc7-b31e-f7128876f3d3@iol.ie> Date: Fri, 25 May 2018 15:15:13 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.8.0 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-GB Content-Transfer-Encoding: 7bit X-SA-Exim-Connect-IP: 93.107.231.214 X-SA-Exim-Mail-From: rod@iol.ie X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on srv01.teladesign.ie X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=ALL_TRUSTED,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Subject: Re: Insert data if it is not existing X-SA-Exim-Version: 4.2.1 (built Mon, 26 Dec 2011 16:24:06 +0000) X-SA-Exim-Scanned: Yes (on srv01.teladesign.ie) X-Host-Lookup-Failed: Reverse DNS lookup failed for 2001:41c9:1:41d::10 (failed) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 25/05/18 14:35, Igor Neyman wrote: > > '''INSERT INTO my_table(name, age) > > VALUES( %s, %s) > > WHERE NOT EXISTS(SELECT name FROM my_table WHERE name=%s)''', ('Scott', > 23, 'Scott')) I haven't been following this thread, so maybe this has already been said, but I think you need a SELECT in there as well: insert into my_table(name, age) select 'value 1', 'value 2' where not exists ( ..... ); Ray. -- Raymond O'Donnell :: Galway :: Ireland rod@iol.ie