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 1fLhbX-0004if-Eg for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 04:11:55 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fLhbW-0006fa-6z for pgsql-general@arkaria.postgresql.org; Thu, 24 May 2018 04:11:54 +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 1fLhbV-0006fR-Rw for pgsql-general@lists.postgresql.org; Thu, 24 May 2018 04:11:54 +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 1fLhbT-00041Z-2J for pgsql-general@lists.postgresql.org; Thu, 24 May 2018 04:11:52 +0000 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id EE1EE21BBF; Thu, 24 May 2018 00:11:49 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute6.internal (MEProxy); Thu, 24 May 2018 00:11:49 -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=yPGR0PZ7aKuWX+xgxqOK5PWkZQvyJ YCcvowp7uWIVks=; b=eNtzL6c8nwJfg64zemdr+McTBP+m4GegrTT1s2PkLd+GH ocsTjy7OAhTX8KLfJboC0Tp+p8LU5fAPdIviYO0ZRCV3qTB/mBVrstV6FhN+Ov8i bWEVTeo2+aGEzRg7AjpJamP9cqs7QzGsn9tEdgwmEwmdfmajTm4ZYCM26J1NaUtH sMcuhwWAWGZgM55EkP97LFWg/qdonOT5CqkTOff8DMvUq+FqnTL+i0tn7S6Lqh7x n3F9m+Y5qBhY+uBBwlcbpJcsLLAKDSBsv1HGyGH8nXtvvr/DY51nXXj097hNgq8+ euWO2QsmKRD5UkIixeawdc9YE/fGjehsrhypxV6aQ== 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=yPGR0P Z7aKuWX+xgxqOK5PWkZQvyJYCcvowp7uWIVks=; b=EmgIIJ1O58NNLwFgeeTMrQ 4i5K/NK4ys/jFpPGMI/yRBSExh95Q4F/vhIdhsAqmb1gLGnVoRUaUJEnJ+lDfXGJ UWjrtqTf87J6EX2ZcYHzHoMR5GmsRqwwAEMI4v+tkN7iJfLj6TWb6JHR4xi1Klj2 +dejYW/wWt2sFg3MSgk4GCKqtaQhons5u7N6TQD52vSlKmA4eb2RYQfqH09vLGT0 Km4k1dUKM17ZCe3PTpIk/yn5xbMS3QwAlSltNIwEvPCcqrdSVD9UiQjrmk1x3g/t rjM7E1XEq2aaJd6h2zoWgXYbwj1K7LHxTq7RJdj2ls9MsnH2xZ41cwFaTW88onww == 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 436CAE44F3; Thu, 24 May 2018 00:11:49 -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: Date: Wed, 23 May 2018 21:11:48 -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 07:59 PM, tango ward wrote: > > > > On Thu, May 24, 2018 at 10:51 AM, Adrian Klaver > Try the example I showed previously. If you do not want to use the > the named parameters e.g %(name)s then use use %s and a tuple like: > > ''' > INSERT INTO my_table(%s, %s) > WHERE NOT EXISTS(SELECT name FROM my_table WHERE name= %s) > ''', (Scott', 23, 'Scott')) > > > > > > Trying to coordinate with Lead Dev about adding Index On The Fly > > > > > > -- > Adrian Klaver > adrian.klaver@aklaver.com > > > Thank you Master, the name=%s solved it. Please show the complete example that worked for completeness. FYI, psql is your friend. When I work out queries I try them in psql first and then move up to whatever interface I will be using. This is usually done on a dev server so mistakes don't bring things down. If I have to work on a production instance then I do: BEGIN; some_query; ROLLBACK; -- Adrian Klaver adrian.klaver@aklaver.com