Re: Catching unique_violation exception on specific column/index

Поиск
Список
Период
Сортировка
От Alexey Dokuchaev
Тема Re: Catching unique_violation exception on specific column/index
Дата
Msg-id 20180611104138.GA43920@regency.nsu.ru
обсуждение исходный текст
Ответ на Catching unique_violation exception on specific column/index  (Alexey Dokuchaev <danfe@nsu.ru>)
Список pgsql-general
On Mon, Jun 11, 2018 at 05:10:33PM +0700, Alexey Dokuchaev wrote:
> The usual approach ("EXCEPTION WHEN unique_violation THEN ... END") does
> not really cut it because I want to catch unique_violation only when it
> happens on "foo_key", and still rightfully complain on others.  However,
> there is no "EXCEPTION WHEN unique_violation ON (foo_key)" or something.
> Is there a way to do this without using triggers and in a less ugly way
> than the code below?

Oh, I completely forgot about rules:

    CREATE OR REPLACE RULE ignore_duplicate_foo AS
      ON INSERT TO table_bar WHERE EXISTS (
        SELECT 1 FROM table_bar WHERE foo = NEW.foo)
      DO INSTEAD NOTHING;

Sorry for the noise.

./danfe


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

Предыдущее
От: Thomas Kellerer
Дата:
Сообщение: Re: Catching unique_violation exception on specific column/index
Следующее
От: Andreas Kretschmer
Дата:
Сообщение: Re: Catching unique_violation exception on specific column/index