How to model an AND/OR logic by relations ? - Mailing list pgsql-general

From Fritz Lehmann-Grube
Subject How to model an AND/OR logic by relations ?
Date
Msg-id 3C46A422.B79ADE22@math.tu-berlin.de
Whole thread Raw
List pgsql-general
Hi all,

I'm setting up a DB in which ( besides normal relations ) an
AND/OR-relation is to be stored:
I have two tables "documents" and "atoms", where a document shall
"depend" upon a logical expression of atoms.
e.g.  (please widen your window for this)
###########################################################################################
###                                            ###
###  document1 "depends" on (atom1 OR atom2) AND (atom1 OR atom3 OR
atom4) AND (atom5)  ###
###                                            ###
###########################################################################################
This is after some normalization - I could also have (.. AND ..) OR (..
AND ..)
I don't have NOT's.

My idea is to have have two extra-tables:

CREATE TABLE or_groups(
       id ... primary key,
       document_id ... references documents
       );

CREATE TABLE dependencies(
       or_id ... references or_groups,
       atom_id ... references atoms
       );

with ( mapping the example )(please widen your window for this)

    | documents        |         | or_groups          |
    | id    | name        |         | id    | document_id |
    | 1    | document1    |         | 1    | 1          |
    |    |        |         | 2    | 1          |
    |    |        |         | 3    | 1          |

    | dependencies        |         | atoms              |
    | or_id    | atom_id    |         | id    | name          |
    | 1    | 1        |         | 1    | atom1          |
    | 1    | 2        |         | 2    | atom2          |
    | 2    | 1        |         | 3    | atom3          |
    | 2    | 3        |         | 4    | atom4          |
    | 2    | 4        |         | 5    | atom5          |
    | 3    | 5        |         |        |          |

Because I'm a novice in Databases and the idea was pure naive intuition
I want to ask, whether this is a standard problem and whether there is a
standard solution.
Am I running into problems ?
Do bad things happen when "documents" and "atoms" are the same table ?

Greetings and Thanx       Fritz

pgsql-general by date:

Previous
From: Alessio Bragadini
Date:
Subject: Re: news.postgresql.org
Next
From: "Nikola Milutinovic"
Date:
Subject: Database encoding in pg_dump