checking data integrity in a recursive table - Mailing list pgsql-sql

From Luke Pascoe
Subject checking data integrity in a recursive table
Date
Msg-id 019801c2c31c$c8d63fa0$3200000a@K2
Whole thread Raw
Responses Re: checking data integrity in a recursive table  (Bruce Momjian <pgman@candle.pha.pa.us>)
List pgsql-sql
Hi, I have a table that references itself to create a tree-like structure,
eg:   CREATE TABLE tree (       id     SERIAL NOT NULL,       name   VARCHAR(255) NOT NULL,       parent INT NULL,
customer IN NOT NULL,       CONSTRAINT parent_key...       CONSTRAINT customer_fk FOREIGN KEY (customer) REFERENCES
customer      );   ALTER TABLE tree ADD CONSTRAINT FOREIGN KEY (parent) REFERENCES tree;
 

As you can see tree also references the customer table.

What I need is a CHECK that will ensuer that any given "tree" row has the
same customer as its parent.
Remember that "parent" can also be NULL.

Or would this be better done as a trigger?

TIA!

========================================
Luke Pascoe
KMG (NZ) Limited. http://www.kmg.co.nz
Mobile: (021) 303019
Email: luke.p@kmg.co.nz
========================================




pgsql-sql by date:

Previous
From: Tom Lane
Date:
Subject: Re: LONG - Question on dealing w/ numerics
Next
From: 71062.1056@compuserve.com (--CELKO--)
Date:
Subject: Re: double linked list