Re: Rule problem: return value of insert

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Rule problem: return value of insert
Дата
Msg-id 20904.1137528147@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Rule problem: return value of insert  (Stephen Friedrich <stephen.friedrich@fortis-it.de>)
Ответы Re: Rule problem: return value of insert  (Stephen Friedrich <stephen.friedrich@fortis-it.de>)
Список pgsql-general
Stephen Friedrich <stephen.friedrich@fortis-it.de> writes:
> In fact I have found some related mails in the archive, but I really do not
> understand why '0' is returned.
> The documentation (34.5. Rules and Command Status) says if I replace an INSERT
> with another INSERT the value returned should be from the new INSERT statement?

Not when you're using a pile of conditional rules like that.  The last
one to fire determines the result, so you'll only see a nonzero count
when inserting into the last subtable.

I think you'd be better off to forget the rule approach and instead
put a trigger on the parent table that stores the values into the
appropriate subtable and then returns NULL.  Unfortunately that won't
fix the rowcount problem either (because suppressed inserts won't be
counted), but it will certainly outperform a large collection of rules.

            regards, tom lane

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: mac os x compile failure
Следующее
От: Stephen Friedrich
Дата:
Сообщение: Re: Rule problem: return value of insert