0

Using Postgres 9.6 I have 2 table, a view that joins them and a rule that inserts into both tables when you try and insert into the view.

It works fine as long as the calling code it does not use the RETURNING clause.

CREATE OR REPLACE RULE insert_my_view
AS ON INSERT TO my_view DO INSTEAD
(
  INSERT INTO tableA(tableA_id, name) VALUES (NEW.tableA_id, NEW.name) RETURNING *, NEW.some_other (or maybe tableB.some_other);
  INSERT INTO tableB(tableA_id, some_other) VALUES (NEW.tableA_id, NEW.some_other);
);

Is there a way to maybe make each insert return it's data and then I join the results for the overall returning statement?

  • 1
    To make views updateable using `instead of` triggers is the recommended approach. –  Oct 26 '18 at 08:21
  • Thanks @IMSoP, I searched and searched and couldn't find the stackoverflow answer. Defo a duplicate question then – Daniel Worthington-Bodart Oct 26 '18 at 08:26
  • @DanielWorthington-Bodart Funnily enough, I found it through the "Related" links on the right-hand-side, but I'm not sure how the magic juice for those works. :) – IMSoP Oct 26 '18 at 10:08

0 Answers0