Re: changing an update via rules - caught in recursion - Mailing list pgsql-general

From Tom Lane
Subject Re: changing an update via rules - caught in recursion
Date
Msg-id 25314.1058391946@sss.pgh.pa.us
Whole thread Raw
In response to changing an update via rules - caught in recursion  (Lauren Matheson <lmatheson@ivcf.ca>)
Responses Re: changing an update via rules - caught in recursion  (Lauren Matheson <lmatheson@ivcf.ca>)
List pgsql-general
Lauren Matheson <lmatheson@ivcf.ca> writes:
> CREATE RULE contactsecgrp_update_1pg_them
> AS ON UPDATE TO contactsecuritygroup
> WHERE NEW.primarygroup=true
> DO
> UPDATE contactsecuritygroup SET primarygroup=false WHERE contact_id =
> NEW.contact_id and securitygroup_id != NEW.securitygroup_id;

You can't do that, because a rule is a macro expanded during query
preparation, and the above is going to lead to infinite recursion
during macro expansion.  (No, the WHERE clause does not stop it,
because the actual value of WHERE is only checked at run time.)

You could make this sort of adjustment in a BEFORE UPDATE trigger,
though.

            regards, tom lane

pgsql-general by date:

Previous
From: "Maksim Likharev"
Date:
Subject: Re: ODBC query problem
Next
From: Tom Lane
Date:
Subject: Re: Install new language - Prev: Re: Are you frustrated with PostgreSQL