Re: UPSERT on a view

2018-03-13 Thread Tom Lane
I wrote: >> On Mon, Mar 12, 2018 at 2:26 PM, Steven Roth wrote: >>> 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? > Don't think it's possible unfortuna

Re: UPSERT on a view

2018-03-13 Thread Tom Lane
Melvin Davidson writes: > On Mon, Mar 12, 2018 at 2:26 PM, Steven Roth wrote: >> Why does the following code raise an error? >> >> CREATE TABLE ttest (x integer); >> CREATE VIEW vtest AS SELECT x FROM ttest; >> CREATE FUNCTION vtest_insert() RETURNS trigger LANGUAGE plpgsql AS $$ >> RAISE 'foo'

Re: UPSERT on a view

2018-03-13 Thread Melvin Davidson
On Tue, Mar 13, 2018 at 10:02 AM, David G. Johnston < david.g.johns...@gmail.com> wrote: > On Tue, Mar 13, 2018 at 6:47 AM, Melvin Davidson > wrote: > >> On Mon, Mar 12, 2018 at 2:26 PM, Steven Roth >> wrote: >> >>> This code raises the error 'foo', even though the insert says DO NOTHING >>> and

Re: UPSERT on a view

2018-03-13 Thread David G. Johnston
On Tue, Mar 13, 2018 at 6:47 AM, Melvin Davidson wrote: > On Mon, Mar 12, 2018 at 2:26 PM, Steven Roth > 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 function

Re: UPSERT on a view

2018-03-13 Thread Melvin Davidson
On Mon, Mar 12, 2018 at 2:26 PM, Steven Roth wrote: > Why does the following code raise an error? > > CREATE TABLE ttest (x integer); > CREATE VIEW vtest AS SELECT x FROM ttest; > CREATE FUNCTION vtest_insert() RETURNS trigger LANGUAGE plpgsql AS $$ > RAISE 'foo' USING ERRCODE='unique_violati

UPSERT on a view

2018-03-13 Thread Steven Roth
Why does the following code raise an error? CREATE TABLE ttest (x integer); CREATE VIEW vtest AS SELECT x FROM ttest; CREATE FUNCTION vtest_insert() RETURNS trigger LANGUAGE plpgsql AS $$ RAISE 'foo' USING ERRCODE='unique_violation'; END $$; CREATE TRIGGER vtest_insert INSTEAD OF INSERT ON vte