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-16 23:17:13 |
Message-ID: | 1163719033.4514.2.camel@dogma.v10.wvs |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | 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
From | Date | Subject | |
---|---|---|---|
Next Message | Jeremy Smith | 2006-11-16 23:25:05 | Re: PostgreSQL: Question about rules |
Previous Message | Tom Lane | 2006-11-16 21:08:02 | Re: How to crash postgres using savepoints |