Re: insert rule not firing on insert with exists subselect
В списке pgsql-general по дате отправления:
| От | Tom Lane |
|---|---|
| Тема | Re: insert rule not firing on insert with exists subselect |
| Дата | |
| Msg-id | 26350.1081888829@sss.pgh.pa.us обсуждение |
| Ответ на | insert rule not firing on insert with exists subselect (Chris Kratz <chris.kratz@vistashare.com>) |
| Ответы |
Re: insert rule not firing on insert with exists subselect
|
| Список | pgsql-general |
Chris Kratz <chris.kratz@vistashare.com> writes:
> create rule mycopyrule as on insert to table2 do insert into table3 (col1)
> values (new.col1);
> insert into table2 (col1) select col1 from table1 where not exists (select 1
> from table2 where table2.col1 = table1.col1); -- doesn't work
The rule-generated query executes after the original INSERT, and can see
its results. So by the time the rule fires, there *is* an entry in
table2 matching the table1 value, and of course the EXISTS condition
fails.
Rules are not triggers and make poor substitutes for them. You're going
to need to use a trigger for this...
regards, tom lane
В списке pgsql-general по дате отправления:
Сайт использует файлы cookie для корректной работы и повышения удобства. Нажимая кнопку «Принять» или продолжая пользоваться сайтом, вы соглашаетесь на их использование в соответствии с Политикой в отношении обработки cookie ООО «ППГ», в том числе на передачу данных из файлов cookie сторонним статистическим и рекламным службам. Вы можете управлять настройками cookie через параметры вашего браузера