How to model an AND/OR logic by relations ?

From: Fritz Lehmann-Grube <lehmannf(at)math(dot)TU-Berlin(dot)DE>
To: pgsql-general(at)postgresql(dot)org
Cc: Erhard Zorn <erhard(at)math(dot)TU-Berlin(dot)DE>, Tilman Rassy <rassy(at)math(dot)TU-Berlin(dot)DE>
Subject: How to model an AND/OR logic by relations ?
Date: 2002-01-17 10:14:58
Message-ID: 3C46A422.B79ADE22@math.tu-berlin.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Nikola Milutinovic 2002-01-17 10:50:14 Database encoding in pg_dump
Previous Message Esger Abbink 2002-01-17 09:34:06 Re: oid problem with dumping database (failed sanity check, opr with oid 280515 was not found)