Re: UPSERT on a view

Поиск
Список
Период
Сортировка
От David G. Johnston
Тема Re: UPSERT on a view
Дата
Msg-id CAKFQuwbx6XTYmvQtpAU=h3ufMHAYnzp4fH6a1Dhx2YXvrZAr5A@mail.gmail.com
обсуждение исходный текст
Ответ на Re: UPSERT on a view  (Melvin Davidson <melvin6925@gmail.com>)
Ответы Re: UPSERT on a view
Список pgsql-general
On Tue, Mar 13, 2018 at 6:47 AM, Melvin Davidson <melvin6925@gmail.com> wrote:
On Mon, Mar 12, 2018 at 2:26 PM, Steven Roth <steve@rothskeller.net> wrote:
This code raises the error 'foo', even though the insert says DO NOTHING and the error type is unique_violation.  Why?

More generally:  how can one write trigger functions for a view (that is not automatically updatable), such that INSERT ... ON CONFLICT DO UPDATE will work with the correct semantics?  What can one do in the INSERT trigger that will cause PostgreSQL to execute the caller-supplied UPDATE clause?


Sorry, not sure...
>CREATE TRIGGER vtest_insert INSTEAD OF INSERT ON vtest
>    FOR EACH ROW EXECUTE PROCEDURE vtest_insert();
>INSERT INTO vtest VALUES (1) ON CONFLICT DO NOTHING;

Your problem is that
A. TRIGGERS are meant for TABLES, not views
and
B. You CANNOT insert into a VIEW.

 
​Your knowledge is this area is out-of-date...you should read the page you linked to again.

I'll admit "table_name" probably could be labelled "relation_name"...though that is then too broad.

David J.
 

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

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Question on corruption (PostgreSQL 9.6.1)
Следующее
От: Melvin Davidson
Дата:
Сообщение: Re: UPSERT on a view