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

Peripheral Links

Header And Logo

PostgreSQL
| The world's most advanced open source database.

Site Navigation

Search archives
  Advanced Search

Re: Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule


  • From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
  • To: Aron <auryn(at)wanadoo(dot)es>
  • Cc: pgsql-sql(at)postgresql(dot)org
  • Subject: Re: Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule
  • Date: Thu, 25 Feb 2010 10:28:56 -0500
  • Message-id: <3702.1267111736@sss.pgh.pa.us> <text/plain>

Aron <auryn(at)wanadoo(dot)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



Home | Main Index | Thread Index

Privacy Policy | About PostgreSQL
Copyright © 1996 – 2012 PostgreSQL Global Development Group