Re: Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule - Mailing list pgsql-sql

From Tom Lane
Subject Re: Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule
Date
Msg-id 3702.1267111736@sss.pgh.pa.us
Whole thread Raw
In response to Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule  (Aron <auryn@wanadoo.es>)
Responses Re: Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule  (Aron <auryn@wanadoo.es>)
List pgsql-sql
Aron <auryn@wanadoo.es> writes:
> I would like to avoid using "SELECT MAX(id) FROM my_table" (it doesn't seem a 
> good method), but if I use "new.id", I get new id values, not the "id" 
> inserted with the rule, and the condition is always false.

"new.id" is a macro, which in this example will be expanded into a
nextval() function call, which is why it doesn't work --- the nextval()
in the WHERE condition will produce a different value from the one in
the original INSERT.  You would be far better off using a trigger here
instead of a rule.
        regards, tom lane


pgsql-sql by date:

Previous
From: Aron
Date:
Subject: Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule
Next
From: silly sad
Date:
Subject: what exactly is a query structure?