Re: infinite recursion detected in rules for relation

From: John McKown <john(dot)archie(dot)mckown(at)gmail(dot)com>
To: pinker <pinker(at)onet(dot)eu>
Cc: PostgreSQL General <pgsql-general(at)postgresql(dot)org>
Subject: Re: infinite recursion detected in rules for relation
Date: 2015-02-12 17:27:34
Message-ID: CAAJSdjjP0o5Er8Jf2Bj6NhdkwM4r3Y7_+n8NvcyrzSoHDGwUdg@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Thu, Feb 12, 2015 at 10:48 AM, pinker <pinker(at)onet(dot)eu> wrote:

> I wanted to set a rule:
>
> CREATE RULE "_RETURN" AS
> ON SELECT * from backend.test
> DO INSTEAD
> SELECT * FROM backend.test WHERE who='Me';
>
> When I'm trying to do anything on the table I get following error:
>
> ERROR: infinite recursion detected in rules for relation "backend.test"
>
> ********** Błąd **********
>
> ERROR: infinite recursion detected in rules for relation "backend.test"
> Stan SQL: 42P17
>
> Is there any way to avoid that? Maybe there exist some other approaches
> that could be useful ?

​I'm not totally sure why you want to do the above. If I needed such a
thing and "backend.test" already exists, I would rename "backend.test" to
something like "backend.test__x" and then create a view like:

CREATE VIEW backend.test AS
SELECT * FROM bachend.test__x WHERE who='Me'
WITH CHECK OPTION.

The WITH CHECK OPTION will stop people from doing a INSERT or UPDATE which
did not have "who" equal to 'Me'. I don't know if you would need this.

I would then GRANT appropriate authority to the VIEW and remove it from
"backend.test__x"​.

--
He's about as useful as a wax frying pan.

10 to the 12th power microphones = 1 Megaphone

Maranatha! <><
John McKown

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David G Johnston 2015-02-12 17:28:12 Re: infinite recursion detected in rules for relation
Previous Message pinker 2015-02-12 16:48:36 infinite recursion detected in rules for relation