pretty much away in time, but i am trying to achieve a similar thing as the original poster. my best idea so far is to store the expression in polish form (operand before operands, no brackets needed), it is much easier to parse after retrieval. another option would be to store the expression as a tree, where the operands and the operators are all nodes (with fields for node type, parent id etc.). i think you only need a single database table for that.