Re: Creating a RULE for UPDATing a VIEW
| От | Tom Lane |
|---|---|
| Тема | Re: Creating a RULE for UPDATing a VIEW |
| Дата | |
| Msg-id | 27650.1241372202@sss.pgh.pa.us обсуждение |
| Ответ на | Creating a RULE for UPDATing a VIEW ("Dean Gibson (DB Administrator)" <postgresql@ultimeth.com>) |
| Список | pgsql-sql |
"Dean Gibson (DB Administrator)" <postgresql@ultimeth.com> writes:
> So, I tried:
> CREATE RULE _update AS ON UPDATE TO public.yyy DO INSTEAD
> (DELETE FROM private.zzz WHERE key_field = OLD.key_field;
> INSERT INTO private.zzz VALUES( NEW.*) );
Nope, won't work, standard gotcha for rules newbies. As soon as you
delete in the first command, the row no longer exists in the view,
and "new.*" is just a macro for a view reference.
AFAIK there really isn't any way to do it except
ON UPDATE DO INSTEADUPDATE private.zzz SET f1 = new.f1, f2 = new.f2, ...WHERE key_field = old.key_field;
BTW, you should also consider adding RETURNING clauses to these
rules so that UPDATE RETURNING &etc will work on the views.
Here at least you can use "RETURNING *" ...
regards, tom lane
В списке pgsql-sql по дате отправления: