Re: Way to stop recursion? - Mailing list pgsql-sql

From Tom Lane
Subject Re: Way to stop recursion?
Date
Msg-id 19345.1101504671@sss.pgh.pa.us
Whole thread Raw
In response to Way to stop recursion?  (Jonathan Knopp <pgsql@delegated.net>)
Responses Re: Way to stop recursion?
Re: Way to stop recursion?
List pgsql-sql
Jonathan Knopp <pgsql@delegated.net> writes:
> CREATE TABLE parent (id INT, cola CHAR(1), common CHAR(1));
> CREATE TABLE child (id INT, parent_id INT, cola(1), common(1));

> What I need, is when "common" is changed for a parent, then that new 
> value is reflected in "common" for all the children, ie:
> ...
> Problem is, when "common" is changed for a child, I need the parent and 
> all siblings to reflect that value too, ie:

Seems to me that your real problem is a bogus database layout.  If there
should only be one "common" value for a parent and children, then only
store one value ... that is, "common" should exist only in the parent.

You can if you like make a view that emulates the appearance of a child
table with a common column, viz

create view childview as select child.*, parent.common from child, parent where parent_id = parent.id;

and it would even be possible to make a rule that allows updating this
view.
        regards, tom lane


pgsql-sql by date:

Previous
From: Jonathan Knopp
Date:
Subject: Way to stop recursion?
Next
From: Andrew Sullivan
Date:
Subject: Re: Way to stop recursion?