How do I use returning in a view?
CREATE RULE ins_productionlog AS ON INSERT TO vwProductionlog DO
INSTEAD
(
INSERT INTO PRODUCTIONLOG
(machine_name,product_serial_id,production_time,product_number,id)
VALUES
(new.machine_name, new.product_serial_id,
new.production_time,new.product_number, DEFAULT) RETURNING
productionlog.machine_name, productionlog.product_serial_id,
productionlog.production_time,
productionlog.product_number, productionlog.id AS foreign_id;
INSERT INTO TTEST (name, id) VALUES (new.name,
vwProductionlog.foreign_id ) ;
);
I have an updateable view (using rules) that I'm trying to improve by
using 8.2's RETURNING feature to place the result of one insert into
the next. I want to be able to put the returning "productionlog.id AS
foreign_id" into table TTEST. Is that even possible just using
RULES? If it is, what would be the correct syntax?
"Karen Hill" <karen_hill22@yahoo.com> writes:
I have an updateable view (using rules) that I'm trying to improve by
using 8.2's RETURNING feature to place the result of one insert into
the next.
That's not what it's for. RETURNING in an insert rule is to define what
to return if someone does an INSERT/RETURNING *on the view*. It's
thrown away if the rule is invoked by a plain INSERT.
regards, tom lane