Re: How to model an AND/OR logic by relations ?

From: "Steve Boyle \(Roselink\)" <boylesa(at)roselink(dot)co(dot)uk>
To: "Fritz Lehmann-Grube" <lehmannf(at)math(dot)TU-Berlin(dot)DE>, <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: Re: How to model an AND/OR logic by relations ?
Date: 2002-01-17 10:59:23
Message-ID: 000a01c19f46$061856b0$c55869d5@dualtower
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Fritz,

Given that you may have to deal with (.. AND ..) OR (..AND ..) does this
imply that you may need to modify relation dependencies to allow a link to
either atoms or further dependencies?

Otherwise I don't see how you can store the nested conditional statements.

P.S. I've never had to do this before (in databases anyway) it looks more
like an AI / Parser type problem. It may be worth looking at some parsing
code to look at the datastructures they use.

steve boyle

----- Original Message -----
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>
Sent: Thursday, January 17, 2002 10:14 AM
Subject: [GENERAL] How to model an AND/OR logic by relations ?

>
> 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
>
> ---------------------------(end of broadcast)---------------------------
> TIP 3: if posting/reading through Usenet, please send an appropriate
> subscribe-nomail command to majordomo(at)postgresql(dot)org so that your
> message can get through to the mailing list cleanly
>

In response to

Browse pgsql-general by date

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