Skip site navigation (1) Skip section navigation (2)

Re: Way to stop recursion?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jonathan Knopp <pgsql(at)delegated(dot)net>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Way to stop recursion?
Date: 2004-11-26 21:31:11
Message-ID: (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
Jonathan Knopp <pgsql(at)delegated(dot)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 =;

and it would even be possible to make a rule that allows updating this

			regards, tom lane

In response to


pgsql-sql by date

Next:From: Andrew SullivanDate: 2004-11-26 21:34:48
Subject: Re: Way to stop recursion?
Previous:From: Jonathan KnoppDate: 2004-11-26 21:03:38
Subject: Way to stop recursion?

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group