How can I store logical expressions using a RDBMS?
I tag objects and would like to be able to build truth statements based on those tags. (These might be considered as
I would use one table
tags(id,name,type,expression,order)
For your example second-hand-goods needs to be calculated before second-hand-offer, all the others can be calculated without any dependencies.
1,'new',1,'',NULL
2,'for_sale',1,'',NULL
3,'used',1,'',NULL
4,'offer',1,'',NULL
5,'second_hand_goods',2,'(!new or used) and for_sale',1
6,'new_offer',2,'new and offer',1
7,'second_hand_offer',2,'second_hand_goods and offer',2
An item could be tagged by only for_sale, calculating would give:
second_hand_goods,second_hand_offer
I would have a function that gives a list of all the tags for the item, including direct tags and calculated ones:
for_sale,second_hand_goods,second_hand_offer