Re: Modified FIFO queue and insert rule - Mailing list pgsql-general

From Alban Hertroys
Subject Re: Modified FIFO queue and insert rule
Date
Msg-id 46B9C145.8040402@magproductions.nl
Whole thread Raw
In response to Modified FIFO queue and insert rule  ("Leif B. Kristensen" <leif@solumslekt.org>)
Responses Re: Modified FIFO queue and insert rule  ("Leif B. Kristensen" <leif@solumslekt.org>)
Re: Modified FIFO queue and insert rule  ("Leif B. Kristensen" <leif@solumslekt.org>)
List pgsql-general
Leif B. Kristensen wrote:
> CREATE RULE placelimit AS
>     ON INSERT TO recent_places DO ALSO
>     DELETE FROM recent_places
>     WHERE
>     -- this clause doesn't work
>     -- (place_fk = NEW.place_fk AND id <> NEW.id) OR
>     id NOT IN (SELECT id FROM recent_places ORDER BY id DESC LIMIT 10);
>
> When I try to use the commented clause above, no records are written to
> the table at all! Why?

Do you use nextval() for that id?
In that case I think you immediately delete the record after inserting
it, as nextval gets called again in the delete statement, and thus id <>
NEW.id.

You should probably use a trigger (a before one maybe) instead of a rule.

--
Alban Hertroys
alban@magproductions.nl

magproductions b.v.

T: ++31(0)534346874
F: ++31(0)534346876
M:
I: www.magproductions.nl
A: Postbus 416
   7500 AK Enschede

// Integrate Your World //

pgsql-general by date:

Previous
From: "Pavel Stehule"
Date:
Subject: Re: List tables in reverse dependancy order
Next
From: "Leif B. Kristensen"
Date:
Subject: Re: Modified FIFO queue and insert rule