Re: PostgreSQL: Question about rules - Mailing list pgsql-general

From Jeff Davis
Subject Re: PostgreSQL: Question about rules
Date
Msg-id 1163814871.4514.48.camel@dogma.v10.wvs
Whole thread Raw
In response to Re: PostgreSQL: Question about rules  ("Jeremy Smith" <postgres@duckwizard.com>)
List pgsql-general
On Fri, 2006-11-17 at 16:42 -0800, Jeremy Smith wrote:
> On 11/17/06, Jeff Davis <pgsql@j-davis.com> wrote:
> >
> > Why do you need so many functions though? Won't one SQL function do the
> > trick?
> >
> > Regards,
> >         Jeff Davis
> >
> >
>
> You're right, one will do the trick - I was thinking update and
> delete, but of course those will be fine with plain rules because they
> don't need to do anything with default values.
>
> Even so, I guess I have to use a trigger+function instead of a real
> rule, and have an INSTEAD DO NOTHING rule for insert so that the
> trigger gets called without error.  Seems like a bit of a kludge; I
> think I may just give up and do all this stuff in application logic
> instead of database logic.
>

For a trigger to work the columns have to match up. You'd have to create
some kind of empty table that you can insert everything you want into,
and have a BEFORE INSERT trigger to take in all the values, pass them
off to child tables, and then return NULL.

That's functionally not much different from having a rule rewrite the
insert into a function call. If you decide to implement it in the
database I think that's the cleanest way. Why do you think a rule that
makes a function call won't work?

Regards,
    Jeff Davis


pgsql-general by date:

Previous
From: Tomas Vondra
Date:
Subject: Re: After Update Triggers
Next
From: Stephen Harris
Date:
Subject: Re: Shutting down a warm standby database in 8.2beta3