Tell me more ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am storing lists of expressions into a MySQL database. Each list is of form

{_String, {_String, _Real}, _Real}

What data format should each column of the database table be?

I am thinking TEXT, TEXT, FLOAT. Any suggestions?

I need to be able to import values back to Mathematica (with SQLExecute[], SQLSelect[], etc.) and be able to work with expressions in Mathematica program.

share|improve this question
4  
What are you aiming for? Minimum packed size, ease of putting things back into MMA, cross compatibility, speed? Could you say a few more words about the requirements? – tkott May 10 '12 at 0:46
For example ToString[x, InputForm] will let you go back to MMA but it would be better to answer @tkott to get a better answer. – FJRA May 10 '12 at 13:13
See addition in the OP. – Problemania May 10 '12 at 15:42

1 Answer

up vote 1 down vote accepted

It sounds like all you are looking for is a generic storage using MySQL. Then your translation of _String to TEXT makes sense, but I would consider _Real as a DOUBLE column, depending on your precision requirements.

Additionally, I would probably separate the inner list:

{_String, {_String, _Real}, _Real}

into:

{_String, _String, _Real, _Real}

So that you would have four columns (TEXT, TEXT, DOUBLE, DOUBLE). You can translate back and forth with some patterns like:

{a_String, b_String, c_Real, d_Real} -> {a, {b, c}, d}

and

{a_String, {b_String, c_Real}, d_Real} -> {a, b, c, d}

Before and after import.

If you need to store MMA expressions, then the most portable way, I believe, is to store them as InputForm, as mentioned by FJRA in the comment to the question. To do so, you would need to do:

ToString[InputForm[expression]]

And then the reverse:

ToExpression[importedString,InputForm]
share|improve this answer
It's a requirement that {_String, _Real} should not be split into two columns. Sorry if I'm not clear with that. Also, the depth and length of the list is indefinite. So separating it is not generally possible. – Problemania May 10 '12 at 20:55
About the pair of transformations ToString[expr, InputForm] and ToExpression[str, InputForm], is it necessary for expressions that's NumericQ True? – Problemania May 10 '12 at 20:57
@MaThEmAtika no, for NumericQ===True, you should be safe saving the data in the float or double mysql column. As for the extra list then I would keep it as a text and use tostring/toexpression – tkott May 10 '12 at 21:19

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.