This is a discussion on postgres rule with where clause within the Pgsql General forums, part of the PostgreSQL category; --> Hi all, i have a problem with rules on a view. I want to use a conditional rule that ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| Hi all, i have a problem with rules on a view. I want to use a conditional rule that will access other tables, but when i use the rule i get the following error: ERROR: cannot insert into a view HINT: You need an unconditional ON INSERT DO INSTEAD rule. My rule looks something like: CREATE RULE zxv_employees_insert AS ON INSERT TO zxv_employees WHERE EXISTS (select * from zxt_other where 1=1) DO INSTEAD insert into zxt_employees (a,b,c,d) values (x,x,x,x); The postgres API tells me that the where clause cannot access another table and can only so something with NEW/OLD. I must do a check for inserting new data on a view. Is there some way i can fix this? thanx |
| ||||
| On Jan 28, 4:13 pm, dennie <dennie.gu...@gmail.com> wrote: > Hi all, > > i have a problem with rules on a view. > I want to use a conditional rule that will access other tables, but > when i use the rule i get the following error: > ERROR: cannot insert into a view > HINT: You need an unconditional ON INSERT DO INSTEAD rule. > > My rule looks something like: > CREATE RULE zxv_employees_insert AS ON INSERT TO zxv_employees > WHERE EXISTS (select * from zxt_other where 1=1) > DO INSTEAD insert into zxt_employees (a,b,c,d) values (x,x,x,x); > > The postgres API tells me that the where clause cannot access another > table and can only so something with NEW/OLD. > > I must do a check for inserting new data on a view. Is there some way > i can fix this? > > thanx I have found the solution. I must use unconditional rule on a view. Then i don't get any errors. It's possible to query other tables in a conditional rule. |