Re: Insert data if it is not existing

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: tango ward <tangoward15(at)gmail(dot)com>, "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
Cc: "pgsql-generallists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Insert data if it is not existing
Date: 2018-05-24 04:07:26
Message-ID: bd9e3f3f-b475-4eba-c6b0-60960ef7b336@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 05/23/2018 08:04 PM, tango ward wrote:
>
> On Thu, May 24, 2018 at 10:55 AM, David G. Johnston
> <david(dot)g(dot)johnston(at)gmail(dot)com <mailto:david(dot)g(dot)johnston(at)gmail(dot)com>> wrote:
>
> On Wednesday, May 23, 2018, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com
> <mailto:adrian(dot)klaver(at)aklaver(dot)com>> 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(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2018-05-24 04:11:48 Re: Insert data if it is not existing
Previous Message tango ward 2018-05-24 03:04:09 Re: Insert data if it is not existing