Re: Using new.id in the WHERE condition of one UPDATE inside ON INSERT rule
В списке pgsql-sql по дате отправления:
| От | 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
|
| Список | 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 по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера