On Fri, Apr 28, 2017 at 2:42 PM, Tom Lane <t...@sss.pgh.pa.us> wrote: > Kevin Grittner <kgri...@gmail.com> writes: >> On Tue, Apr 25, 2017 at 6:17 PM, Thomas Munro >> <thomas.mu...@enterprisedb.com> wrote: >>> For views, aside from the question of transition tables, I noticed >>> that statement triggers don't seem to fire at all with updatable >>> views. Surely they should -- isn't that a separate bug? > >> I checked out 25dc142a (before any of my commits for $subject), >> built it, and tried the above -- with no warning generated. I then >> used an UPDATE and DELETE against the view, also with no trigger >> fired (nor any error during trigger creation or DML). Does anyone >> know whether such trigger ever fired at any point in the commit >> history? > > [ experiments... ] They did, and do, fire if you do it the old-style > way with an INSTEAD OF row trigger.
Here is the table from near the start of CREATE TRIGGER docs, "folded" such that I hope it remains intelligible in a fixed-width font after email systems get done with it: When Event Row-level Statement-level BEFORE INSERT/UPDATE/DELETE Tables and foreign tables Tables, views, and foreign tables TRUNCATE — Tables AFTER INSERT/UPDATE/DELETE Tables and foreign tables Tables, views, and foreign tables TRUNCATE — Tables INSTEAD OF INSERT/UPDATE/DELETE Views — TRUNCATE — — The claim seems to be that you can create a { BEFORE | AFTER } { event [ OR ... ] } ... FOR EACH STATEMENT trigger where event is { INSERT | UPDATE | DELETE } on an updateable view. Well, you can *create* it, but it will never fire. > They don't fire if you're relying > on an updatable view. It seems we fire the table's statement triggers > instead, ie, the update is fully translated into an update on the > underlying table. Well, certainly that should *also* happen. Not firing a table's DML because it was fired off a view would be crazy, or so it seems to me. > I'm not sure how intentional that was, but it's not a completely > unreasonable definition on its face, and given the lack of field > complaints since 9.3, I think we should probably stick to it. Are you talking about being able to create INSERT, UPDATE, and DELETE triggers on the view (which never fire), or about firing triggers on the table when an INSTEAD OF trigger is fired. > However, if you didn't understand that from the documentation, > then we have a documentation problem. I totally get that there are INSTEAD OF triggers and have no quibble with how they behave. I can't even argue that the above chart is wrong in terms of what CREATE TRIGGER allows. However, creating triggers that can never fire seems entirely wrong. >> If we do get these working, don't they deserve at least >> one regression test? > > Are you sure there isn't one? Well, I was sort of hoping that the triggers that can now be defined but can never fire *did* fire at some point. But if that were true, and they subsequently were broken, it would mean we lacked regression tests for that case. -- Kevin Grittner VMware vCenter Server https://www.vmware.com/ -- Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-hackers