Обсуждение: Rules and Views

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

Rules and Views

От
"Travis Hoyt"
Дата:
Can anyone give me a clue as to how to get rules working with views?  I
have a large table I call 'sardata' and several views, an example of
which is 'sun_u'.  What I want to do is insert data into 'sun_u' and
have it in turn actually update the 'sardata' table.  I've looked at the
examples on the postgresql web page but when I try those examples it
complains, saying "Attribute 'usr' not found" with 'usr' being my first
column.  Here is a copy of one of my attempts:

create rule ins_sun_u as on insert
sarweb-> to sun_u do instead insert into sardata values ( usr, sys, wio,
idle, time, systemid );
ERROR:  Attribute 'usr' not found

Any help would be greatly appreciated.

Thanks,

Travis

Вложения

Re: Rules and Views

От
Tom Lane
Дата:
"Travis Hoyt" <thoyt@npc.net> writes:
> create rule ins_sun_u as on insert
> to sun_u do instead insert into sardata values ( usr, sys, wio,
> idle, time, systemid );
> ERROR:  Attribute 'usr' not found

You need to write "new.usr", etc.  Essentially, "new" and "old" are
record variables referring to the about-to-be-inserted row (in INSERT
or UPDATE rules) and the about-to-be-deleted row (in UPDATE or DELETE).
Even though sun_u is a view not a real table, you still have to follow
the syntax...

            regards, tom lane