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 1fLhXN-0004Qu-EE for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 04:07:37 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fLhXM-0001zx-1w for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 04:07:36 +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 1fLhXK-0001zn-04 for pgsql-general@lists.postgresql.org; Thu, 24 May 2018 04:07:35 +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 1fLhXG-0003v2-BP for pgsql-general@lists.postgresql.org; Thu, 24 May 2018 04:07:32 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id 6938C20DF7; Thu, 24 May 2018 00:07:28 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 24 May 2018 00:07:28 -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=zuubCswoCNOk8muYvacMhrs5zAfNt 5AfUQxp2sypvx8=; b=1B1O9qnypTSoP9ZMSMv/vaOXd9AQgTr0eRnBqRDFU82O8 wW9EaqhQ9vx/hIRg128saYYvgc19+QY2MgGG8EVpYwCctKt6gr63Q/Is+MaDlTtC LsaA8vtFFMnw/s5twK2B3DiHQZCO0Zr36YC+W1yIK16U2VgS7c2OS8rmCJwwo3HZ wWtckJw9yIv2V5k4/gHPV5RJSvPTfzgc77gO1pMQtHvPWOc9K2U+kGfeBY7NE9B8 ToqeIv9ZCij7z/P4uIMz30YbZAb7jtF1LMel1zZLOqQKW4LSJBABwCnCZK8DQ23g zX0PoruGvNU78/gIuAuk7l7xIbl26w/OONv5KHbUg== 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=zuubCs woCNOk8muYvacMhrs5zAfNt5AfUQxp2sypvx8=; b=A1ReSfvd9uhgMc1Lo0R97c fsNzuXWGxrjp68qQnLyC2LCz8Go8gqBbQWTCvwYDasNshu7/JtzgEgW58MGZAMji ZKfaQo4aFTfRkSPEiQ8qeMQFDehi1tKi2lN1ebSRQ1Qb6MLLk7S8z295NbPP65Tg QgBeCZEIgSmC2Dudm1AWlaj5fUeuOo7R0Ps76bqj/icuwBa3sBfR93ULls/zHhn5 LxpWiATfdzAQ4u11etBcm2AFwfAfQbA+o3wSDmu1DU1Sw0+lsdW00rl6it+MX9JT Nq/ugDJJqYQNi1sk1qeqpG2qvNrPbQ8L0tz0ol8G6aX4zhyRNajg7+wkH7js7W9w == 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 94EF9E42DB; Thu, 24 May 2018 00:07:27 -0400 (EDT) Subject: Re: Insert data if it is not existing To: tango ward , "David G. Johnston" Cc: "pgsql-generallists.postgresql.org" References: <0a76f762-88d8-75a7-de3c-d76094638fdd@aklaver.com> From: Adrian Klaver Message-ID: Date: Wed, 23 May 2018 21:07:26 -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: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk On 05/23/2018 08:04 PM, tango ward wrote: > > On Thu, May 24, 2018 at 10:55 AM, David G. Johnston > > wrote: > > On Wednesday, May 23, 2018, Adrian Klaver > wrote: > > INSERT INTO my_table(%s, %s) > WHERE NOT EXISTS(SELECT name FROM my_table WHERE name= %s) > > > INSERT doesn't have a where clause... > > David J. > > > > What I did is > > '''INSERT INTO my_table(name, age) > SELECT %s, %s > WHERE NOT EXISTS(SELECT name FROM my_table WHERE name=%s)''', ('Scott', 23) > I doubt that worked, you have three parameter markers(%s) and two parameter values. Not only that two of the markers are for identifiers. -- Adrian Klaver adrian.klaver@aklaver.com