Re: Insert data if it is not existing - Mailing list pgsql-general

From Raymond O'Donnell
Subject Re: Insert data if it is not existing
Date
Msg-id 11c14f05-ebe6-cbc7-b31e-f7128876f3d3@iol.ie
Whole thread Raw
In response to RE: Insert data if it is not existing  (Igor Neyman <ineyman@perceptron.com>)
List 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@iol.ie


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: case statement within insert
Next
From: Adrian Klaver
Date:
Subject: Re: case statement within insert