Re: changing an update via rules - caught in recursion

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Lauren Matheson <lmatheson(at)ivcf(dot)ca>
Cc: pg_general <pgsql-general(at)postgresql(dot)org>
Subject: Re: changing an update via rules - caught in recursion
Date: 2003-07-16 21:45:46
Message-ID: 25314.1058391946@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Lauren Matheson <lmatheson(at)ivcf(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2003-07-16 22:01:57 Re: Install new language - Prev: Re: Are you frustrated with PostgreSQL
Previous Message Maksim Likharev 2003-07-16 21:45:31 Re: ODBC query problem