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 01:54:31
Message-ID: 1163814871.4514.48.camel@dogma.v10.wvs
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Fri, 2006-11-17 at 16:42 -0800, Jeremy Smith wrote:
> On 11/17/06, Jeff Davis <pgsql(at)j-davis(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Stephen Harris 2006-11-18 02:22:05 Re: Shutting down a warm standby database in 8.2beta3
Previous Message Josh Berkus 2006-11-18 01:30:00 Re: [GENERAL] Allowing SYSDATE to Work