Re: PostgreSQL: Question about rules

From: Jeff Davis <pgsql(at)j-davis(dot)com>
To: Jeremy Smith <postgres(at)duckwizard(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: PostgreSQL: Question about rules
Date: 2006-11-18 00:05:33
Message-ID: 1163808334.4514.39.camel@dogma.v10.wvs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2006-11-18 00:26:45 Re: After Update Triggers
Previous Message Matt Miller 2006-11-18 00:05:29 Re: [GENERAL] Allowing SYSDATE to Work