For this project, like previous VALVE work, we want to validate that a given value falls under another value in a simple hierarchy. We use a tree() function to define the hierarchy, then the under() function to specify which tree and which value must be an ancestor.
As in previous VALVE work, we specify the tree(column) structure on the "parent" column, and the argument is the name of the "child" column. Each child may have a parent, and each parent must appear in the child column. Then we can use a WITH RECURSIVE query to get all the ancestors (or descendants, children, parents) of a given node.
For this to work:
the child column must have distinct values (uniqueness)
the child column must act as a foreign key constraint for the parent column ("foreign" sounds strange since the two columns are in the same table)
the parent column must have the same datatype as the child column
the tree should not contain cycles
Eventually we want to support multiple parents, which changes our tree to a directed acyclic graph (DAG).
For this project, like previous VALVE work, we want to validate that a given value falls under another value in a simple hierarchy. We use a
tree()
function to define the hierarchy, then theunder()
function to specify which tree and which value must be an ancestor.As in previous VALVE work, we specify the
tree(column)
structure on the "parent" column, and the argument is the name of the "child" column. Each child may have a parent, and each parent must appear in the child column. Then we can use a WITH RECURSIVE query to get all the ancestors (or descendants, children, parents) of a given node.For this to work:
Eventually we want to support multiple parents, which changes our tree to a directed acyclic graph (DAG).