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

From David G. Johnston
Subject Re: Insert data if it is not existing
Date
Msg-id CAKFQuwZmEWd7A6n0pbKRFm2XPPUOFeM9qVUphs_P8FwhNDwarQ@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  (Adrian Klaver <adrian.klaver@aklaver.com>)
List pgsql-general
On Wednesday, May 23, 2018, Adrian Klaver <adrian.klaver@aklaver.com> wrote:

'''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.


The count is indeed off but the two markers after the main select are literals, not identifiers.  As is the one being compared to name.

SELECT 'Scott', 23;

is a valid query.

David J. 

pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: Insert data if it is not existing
Next
From: Andrey Borodin
Date:
Subject: Re: Error on vacuum: xmin before relfrozenxid