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

From tango ward
Subject Re: Insert data if it is not existing
Date
Msg-id CAA6wQLKgqo9fvyfnsPNL3gmO=1JrN65d6LCcDaH61AreCysptg@mail.gmail.com
Whole thread Raw
In response to Re: Insert data if it is not existing  (Adrian Klaver <adrian.klaver@aklaver.com>)
Responses RE: Insert data if it is not existing
List pgsql-general

On Thu, May 24, 2018 at 9:38 PM, Adrian Klaver <adrian.klaver@aklaver.com> wrote:
On 05/23/2018 06:03 PM, tango ward wrote:


Updated my code to this:

curr.pgsql.execute('''
INSERT INTO my_table(name, age)
SELECT %s, %s
WHERE NOT EXISTS(SELECT name FROM my_table WHERE name= name)
''', ('Scott', 23))

If I remove SELECT statement, I will get an error message: error : psycopg2.ProgrammingError: syntax error at or near "WHERE"
LINE 12:                         WHERE NOT EXISTS

Trying to coordinate with Lead Dev about adding Index On The Fly

I tried to figure how to make this work and could not, so I led you down a false path.






--
Adrian Klaver
adrian.klaver@aklaver.com

What I tried is

'''INSERT INTO my_table(name, age)
SELECT %s, %s,
WHERE NOT EXISTS(SELECT name FROM my_table WHERE name=%s)''', ('Scott', 23, 'Scott'))

pgsql-general by date:

Previous
From: Andrew Bartley
Date:
Subject: Re: Performance opportunities for write-only audit tables?
Next
From: Michael Paquier
Date:
Subject: Re: Streaming Replication between PostGreSQL 9.2.2 on Red Hat andPostGreSQL 9.2.24 on Debian