Re: PostgreSQL: Question about rules

Поиск
Список
Период
Сортировка
От Jeff Davis
Тема Re: PostgreSQL: Question about rules
Дата
Msg-id 1163808334.4514.39.camel@dogma.v10.wvs
обсуждение исходный текст
Ответ на Re: PostgreSQL: Question about rules  ("Jeremy Smith" <postgres@duckwizard.com>)
Ответы Re: PostgreSQL: Question about rules
Список pgsql-general
On Fri, 2006-11-17 at 11:49 -0800, Jeremy Smith wrote:

> Now, the default value for new.id gets evaluated *each time* I
> reference new.id - meaning the rule's first insert sees N for new.id
> while the rule's second insert sees N+1.  That is kind of odd - I
> would think that the default value would get evaluated and then
> assigned to new.id (since it is a concrete row), but that appears not
> to be the case.
>
> My stopgap solution to this is to call a PSQL/PL function for the body
> of the rule, which can store new.id in a variable so it is evaluated
> only once.  If there is a way to do this inside the rule without
> resorting to creating a view, 3 rules and 3 functions for every child
> table, I would love to hear about it!
>

I think you're operating on the edge of what rules are supposed to do. A
rule won't copy values or create variables, which is why you needed
COALESCE.

Why do you need so many functions though? Won't one SQL function do the
trick?

Regards,
    Jeff Davis


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

Предыдущее
От: Ron Johnson
Дата:
Сообщение: Re: Allowing SYSDATE to Work
Следующее
От: Adrian Klaver
Дата:
Сообщение: Re: After Update Triggers