Re: Why no INSTEAD OF triggers on tables? - Mailing list pgsql-hackers

From Marko Tiikkaja
Subject Re: Why no INSTEAD OF triggers on tables?
Date
Msg-id 52B00AF9.6040700@joh.to
Whole thread Raw
In response to Re: Why no INSTEAD OF triggers on tables?  (Robert Haas <robertmhaas@gmail.com>)
Responses Re: Why no INSTEAD OF triggers on tables?
List pgsql-hackers
On 12/17/13, 4:53 AM, Robert Haas wrote:
>> Well, I'm specifically thinking of master partition tables.  In that
>> case, we really want an INSTEAD OF trigger.
>
> /me scratches head.
>
> So, put a BEFORE trigger, and make it return NULL.  Same effect,
> different notation.

But it's not the same effect at all, that's the point:

=# create view foov as select 1 as a;
CREATE VIEW

=# create function insteadof() returns trigger as $$
$# begin
$# -- INSERT here
$# return new;
$# end
$# $$ language plpgsql;
CREATE FUNCTION

=# create function before() returns trigger as $$
$# begin
$# -- INSERT here
$# return null;
$# end
$# $$ language plpgsql;
CREATE FUNCTION

=# create trigger t1 instead of insert on foov for each row execute 
procedure insteadof();
CREATE TRIGGER

=# create trigger t2 before insert on bart for each row execute 
procedure before();
CREATE TRIGGER

=# insert into foov values (1) returning *; a
--- 1
(1 row)

INSERT 0 1

local:marko=#* insert into bart values (1) returning *; a
---
(0 rows)

INSERT 0 0



Regards,
Marko Tiikkaja



pgsql-hackers by date:

Previous
From: "imagenesis@gmail.com"
Date:
Subject: Re: dpkg-buildpackage fails on 9.2.6 on ubuntu 12.04.3 LTS
Next
From: Andres Freund
Date:
Subject: Re: Changeset Extraction Interfaces