views:

54

answers:

2

If it is how can i query on double and date, I mean there has to be a way to cast them back and them sort them for example.

+1  A: 

Sure, this can be done, but why do you need to do that, when data types exist that do it for you more reliably and with better performance?

I think I smell the EAV antipattern here...

But to answer your question, you can cast a string containing numbers to the actual numeric value like this:

SELECT '123.456' + 0.0;

You can cast a string containing a date literal to the actual date data type with the STR_TO_DATE() function:

SELECT STR_TO_DATE('Nov 12, 2009', '%M %d,%Y');
Bill Karwin
+1  A: 

No, it is not okay. You should use the appropriate data types. According to the MySQL Reference Manual, for storing dates and/or times, you have available to you DATETIME, DATE, TIMESTAMP, TIME, and YEAR. For doubles, there are various numeric types.

Storing doubles and dates into VARCHAR fields can only get you into trouble, and cause performance problems in addition.

shoover
While it's generally indeed "not ok", you don't always have a choice: http://en.wikipedia.org/wiki/Entity-attribute-value_model
ChssPly76