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 1fLqSW-0006OJ-Qg for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 13:39:12 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fLqSU-0005zw-IK for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 13:39:10 +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 1fLqSU-0005zk-6e for pgsql-general@lists.postgresql.org; Thu, 24 May 2018 13:39:10 +0000 Received: from out4-smtp.messagingengine.com ([66.111.4.28]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fLqSM-0008Ou-7i for pgsql-general@lists.postgresql.org; Thu, 24 May 2018 13:39:08 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id D650621F64; Thu, 24 May 2018 09:38:58 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 24 May 2018 09:38:58 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; bh=s2uyzFzqm/F9hzkfuzLf1cbevgeeY ivAMLPtDmMkbrU=; b=izphsEWBKzkCR/0GvUsZTNyWQvpe480X/k6q/H89Vgpj3 2gxdQ0pkPEL8RHaJaAmK5yoqe8nvjRea7h/EUge0Vp5ySG1MByQocFItMSmyHAhY bxrAyhQdilKwOdhKfxBC8KMHikZZE1U6LxwBEJMdDQvZwDcvJpFvh65L3iCATXoK Mu+xsYd+DRThT1iuce2GiEpjdpdUn+tv60FW9AgY0vxIznfd5IZbdh9+q7rLKN69 05nGAi/g6mMxVjAfSHg2e3usfVmwEDPU1meHi0V7WBRlShkmIhgja20d6Xyo0f4k tqlzoUsbwQ2il3/l8XS4kRNfQ9MiXYF3IURytt5ew== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=s2uyzF zqm/F9hzkfuzLf1cbevgeeYivAMLPtDmMkbrU=; b=XMZMTYqMYiGw87TuLZ5K6l jcUvLDqFRx41KnMziJGxReE71C+fSEP5Wx8yFQAmWaANGSJP9QHaLFnyuEC66N1H GvF6e5hUJaIZPLE/NWJEMYynrgAI8KwFKHBy+xkpenqMBOMm/VIZWq5jUlI1ebp8 Cz5kyDUZA1pmX/5ttxA7rEb4XCZ6k3wLfRTygO50GRe2G8aW+8aVPRT22d42p3as KcXee+tXaR4vSGjxGtkKAokkkNOu18r4UIxDhb5RDXftS0E7dggHfrlW1fi+OyjI 2pPiQFdTs80k1dGVfyb50MNBPisHfwr1yPh7aVQwYsQ02dbv9rk87yTqKlN7dssw == X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Proxy: X-ME-Sender: Received: from [192.168.1.2] (unknown [71.212.135.74]) by mail.messagingengine.com (Postfix) with ESMTPA id 37D8AE476D; Thu, 24 May 2018 09:38:58 -0400 (EDT) Subject: Re: Insert data if it is not existing To: tango ward Cc: "David G. Johnston" , "pgsql-generallists.postgresql.org" References: <0a76f762-88d8-75a7-de3c-d76094638fdd@aklaver.com> From: Adrian Klaver Message-ID: <6f46b2b5-c69a-fa85-a66b-8ff318a82aa1@aklaver.com> Date: Thu, 24 May 2018 06:38:57 -0700 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-US Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 05/23/2018 06:03 PM, tango ward wrote: > > Updated my code to this: > > curr.pgsql.execute(''' > INSERT INTO my_table(name, age) > SELECT %s, %s > WHERE NOT EXISTS(SELECT name FROM my_table WHERE name= name) > ''', ('Scott', 23)) > > If I remove SELECT statement, I will get an error message: error : > psycopg2.ProgrammingError: syntax error at or near "WHERE" > LINE 12:                         WHERE NOT EXISTS > > Trying to coordinate with Lead Dev about adding Index On The Fly I tried to figure how to make this work and could not, so I led you down a false path. > > > -- Adrian Klaver adrian.klaver@aklaver.com