RULE and more than 10 rewrites.

From: Vegard Munthe <vegard(at)copyleft(dot)no>
To: pgsql-general(at)postgresql(dot)org
Subject: RULE and more than 10 rewrites.
Date: 2003-01-22 17:17:11
Message-ID: 20030122181010.Q26393-100000@unity.copyleft.no
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


I have a RULE that does 18 rewrites. This is a RULE that saves me alot of
work when rewriting some software, but the RULE always fails since PGSQL
seems tp think 10 or more rewrites constitutes a loop.

"ERROR: query rewritten 10 times, may contain cycles"

Is there any way I can set the rewrite limit to more than 10, say 100,
which would be more of a safeguard number for loops?

If not, should I use a trigger on the view the RULE is working on at the
moment?

For those interested my rule looks like this:
---
CREATE RULE person_update AS ON UPDATE TO person_view DO INSTEAD
(
UPDATE attribute SET value = new.firstname WHERE
attrtype = 'firstname' AND objectid = old.id;
UPDATE attribute SET value = new.middlename WHERE
attrtype = 'middlename' AND objectid = old.id;
UPDATE attribute SET value = new.lastname WHERE
attrtype = 'lastname' AND objectid = old.id;
UPDATE attribute SET value = new.nickname WHERE
attrtype = 'nickname' AND objectid = old.id;
UPDATE attribute SET value = new.membernumber WHERE
attrtype = 'membernumber' AND objectid = old.id;
UPDATE attribute SET value = new.streetaddress WHERE
attrtype = 'streetaddress' AND objectid = old.id;
UPDATE attribute SET value = new.zipcode WHERE
attrtype = 'zipcode' AND objectid = old.id;
UPDATE attribute SET value = new.city WHERE
attrtype = 'city' AND objectid = old.id;
UPDATE attribute SET value = new.country WHERE
attrtype = 'country' AND objectid = old.id;
UPDATE attribute SET value = new.phone WHERE
attrtype = 'phone' AND objectid = old.id;
UPDATE attribute SET value = new.email WHERE
attrtype = 'e-mail' AND objectid = old.id;
UPDATE attribute SET value = new.mobilephone WHERE
attrtype = 'mobilephone' AND objectid = old.id;
UPDATE attribute SET value = new.dept WHERE
attrtype = 'dept' AND objectid = old.id;
UPDATE attribute SET value = new.fromdate WHERE
attrtype = 'fromdate' AND objectid = old.id;
UPDATE attribute SET value = new.birthday WHERE
attrtype = 'birthday' AND objectid = old.id;
UPDATE attribute SET value = new.username WHERE
attrtype = 'username' AND objectid = old.id;
UPDATE attribute SET value = new.password WHERE
attrtype = 'password' AND objectid = old.id;
UPDATE attribute SET value = new.language WHERE
attrtype = 'language' AND objectid = old.id
);
---

(Pretty ugly huh?)

-- Vegard Munthe

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Csaba Nagy 2003-01-22 17:57:58 Re: Postgres (psql ?) rounds all odd second values to e
Previous Message David Blood 2003-01-22 17:07:06 agregates