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

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',

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

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

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