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

From Jeff Davis
Subject Re: PostgreSQL: Question about rules
Date
Msg-id 1163719033.4514.2.camel@dogma.v10.wvs
Whole thread Raw
In response to PostgreSQL: Question about rules  ("Jeremy Smith" <postgres@duckwizard.com>)
Responses Re: PostgreSQL: Question about rules  ("Jeremy Smith" <postgres@duckwizard.com>)
List pgsql-general
On Thu, 2006-11-16 at 11:34 -0800, Jeremy Smith wrote:
> Example:
>
> ------------------------ Begin example SQL
> create table parent (
>     id serial primary key,
>     foo integer,
> );
>
> create table child (
>     id integer references parent(id) on delete cascade,
>     bar integer
> )
>
> create view child_with_parent_explicit as
>     select parent.id, parent.foo, child.bar from parent join child using(id);
>
> -- this next one is just a copy of the first, to differentiate the two scenarios
> create view child_with_parent_implicit as
>     select parent.id, parent.foo, child.bar from parent join child using(id);
>
> create rule "child_with_parent_explicit_insert" as
>     on insert to child_with_parent_explicit do instead (
>         insert into parent(id, foo) values(new.id, new.foo);
>         insert into child(id, bar) values(new.id, new.bar);
>     );
>

create rule "child_with_parent_explicit_insert" as
        on insert to child_with_parent_explicit do instead (
                insert into parent(id, foo) values(COALESCE
(new.id,NEXTVAL('parent_id_seq')), new.foo);
                insert into child(id, bar) values(COALESCE
(new.id,CURRVAL('parent_id_seq')), new.bar);
        );


I'm not sure if this is what you're looking for, but does this help?

Regards,
    Jeff Davis


pgsql-general by date:

Previous
From: "Gurjeet Singh"
Date:
Subject: Re: [HACKERS] Not your father's question about deadlocks
Next
From: "Jeremy Smith"
Date:
Subject: Re: PostgreSQL: Question about rules