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

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule
Дата
Msg-id 3702.1267111736@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule  (Aron <auryn@wanadoo.es>)
Ответы Re: Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule  (Aron <auryn@wanadoo.es>)
Список 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 по дате отправления:

Предыдущее
От: Aron
Дата:
Сообщение: Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule
Следующее
От: silly sad
Дата:
Сообщение: what exactly is a query structure?