How do I use returning in a view?

Поиск
Список
Период
Сортировка
Искать

How do I use returning in a view?

От:
"Karen Hill" <karen_hill22@yahoo.com>
Дата:
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?

Re: How do I use returning in a view?

От:
Tom Lane <tgl@sss.pgh.pa.us>
Дата:
"Karen Hill"  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
FAQ