Re: SQL( "if ...exists...),how to do it in the PostgreSQL?

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: SQL( "if ...exists...),how to do it in the PostgreSQL?
Дата
Msg-id 24541.991843129@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: SQL( "if ...exists...),how to do it in the PostgreSQL?  (Peter Eisentraut <peter_e@gmx.net>)
Список pgsql-hackers
>> if not exists(select id from test) insert into test(id) values (280);

> Write a function in PL/pgSQL.

That particular case could be handled like so:

insert into test(id) select 280 where not exists(select id from test);

The select produces either zero or one row depending on whether its
WHERE is true.  Voila, problem solved.  It's even nearly standard ;-)
although in something like Oracle you'd have to add "from dual", I
think.
        regards, tom lane


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

Предыдущее
От: Peter Eisentraut
Дата:
Сообщение: Re: Can the backend return more than one error message per PQexec?
Следующее
От: KuroiNeko
Дата:
Сообщение: Re: Max inserts / sec ... on any platform?