Re: Insert data if it is not existing

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Igor Neyman <ineyman(at)perceptron(dot)com>, tango ward <tangoward15(at)gmail(dot)com>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
Cc: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, "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-25 14:15:13
Message-ID: 11c14f05-ebe6-cbc7-b31e-f7128876f3d3@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

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(at)iol(dot)ie

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2018-05-25 14:19:55 Re: case statement within insert
Previous Message Adrian Klaver 2018-05-25 14:05:32 Re: case statement within insert