Skip site navigation (1) Skip section navigation (2)

Re: is it a bug in rule system?

From: Martijn van Oosterhout <kleptog(at)svana(dot)org>
To: laser <laserlist(at)pgsqldb(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: is it a bug in rule system?
Date: 2008-05-28 11:14:19
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-general
On Wed, May 28, 2008 at 04:59:33PM +0800, laser wrote:
> >Yes, use a TRIGGER instead a RULE for such tasks.
> thanks, good to know it's a bug and we'll try TRIGGER approach.

It's not a bug, just your misunderstanding of how rules work. Rules
rewrite queries. What happen in your case is because of the condition
your query will be split into two: once with your INSERT with a NOT
EXISTS (subquery) and once as an UPDATE with the condition EXISTS

So the first query will insert with id=1 and then the update sees this
row and updates it to 2.

What this says is that rules are the wrong tool for what you're trying
to do. Conditional rules are powerful but not appropriate here.

Have a nice day,
Martijn van Oosterhout   <kleptog(at)svana(dot)org>
> Please line up in a tree and maintain the heap invariant while 
> boarding. Thank you for flying nlogn airlines.

In response to


pgsql-general by date

Next:From: Francisco ReyesDate: 2008-05-28 14:53:27
Subject: Re: Psql crashes with Segmentation fault on copy from
Previous:From: laserDate: 2008-05-28 08:59:33
Subject: Re: is it a bug in rule system?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group