Re: Insert data if it is not existing

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: Insert data if it is not existing
Дата
Msg-id CAKFQuwZ1AsufoP62r1cF6sQGg5hu1USqvjdeata-NXU9Rr=NKQ@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Insert data if it is not existing  (tango ward <tangoward15@gmail.com>)
Ответы Re: Insert data if it is not existing  (tango ward <tangoward15@gmail.com>)
Список pgsql-general
On Wednesday, May 23, 2018, tango ward <tangoward15@gmail.com> wrote:


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))

So, WHERE name = name is ALWAYS true and so as long as there is at least one record in my_table the exists returns true, and the not inverts it to false and the main select returns zero rows.  You have successfully inserted a record that doesn't exist (i.e., you've inserted nothing just like you observe).

David J.

В списке pgsql-general по дате отправления:

Предыдущее
От: tango ward
Дата:
Сообщение: Re: Insert data if it is not existing
Следующее
От: tango ward
Дата:
Сообщение: Re: Insert data if it is not existing