Comments on: Type conversion semantics of MySQL’s BETWEEN operator http://www.xaprb.com/blog/2006/09/12/type-conversion-semantics-of-mysqls-between-operator/ Stay curious! Fri, 10 May 2013 18:25:19 +0000 hourly 1 http://wordpress.org/?v=3.5.1 By: mikec http://www.xaprb.com/blog/2006/09/12/type-conversion-semantics-of-mysqls-between-operator/#comment-14226 mikec Mon, 18 Feb 2008 19:50:40 +0000 http://www.xaprb.com/blog/?p=221#comment-14226 I mean mysql does NOT always convert operands of between to the type of the first one in my previous post.

]]>
By: mikec http://www.xaprb.com/blog/2006/09/12/type-conversion-semantics-of-mysqls-between-operator/#comment-14225 mikec Mon, 18 Feb 2008 19:47:36 +0000 http://www.xaprb.com/blog/?p=221#comment-14225 Here is an example that shows mysql does convert between operators to the type of the first one.
select * from t1
where ’5′ between 3 and ’10′;

The first operand is a string, if mysql convert 3 to string and using string comparison , it would return empty table because ’5′

]]>
By: Xaprb http://www.xaprb.com/blog/2006/09/12/type-conversion-semantics-of-mysqls-between-operator/#comment-4129 Xaprb Fri, 16 Feb 2007 14:17:14 +0000 http://www.xaprb.com/blog/?p=221#comment-4129 Hi shawnc, you are facing problems because your data is not properly normalized; there is no such thing as an “array” in SQL. I recommend you read on normalization. MySQL has a very good article on normalization, and there are others as well. If you are still having troubles, try connecting to #mysql on IRC — you are likely to have a series of questions as you learn SQL’s initially awkward way to do things.

]]>
By: shawnc http://www.xaprb.com/blog/2006/09/12/type-conversion-semantics-of-mysqls-between-operator/#comment-4124 shawnc Fri, 16 Feb 2007 12:10:42 +0000 http://www.xaprb.com/blog/?p=221#comment-4124 Hello, I am trying to solve a problem where my data inside the table is stored in a array of 1,2,3,4,5,6 I need to check if a user entered number is within this array. Is this possible with the between operator?

]]>
By: Xaprb http://www.xaprb.com/blog/2006/09/12/type-conversion-semantics-of-mysqls-between-operator/#comment-1793 Xaprb Wed, 13 Sep 2006 13:48:32 +0000 http://www.xaprb.com/blog/?p=221#comment-1793 Something I inferred, but didn’t write very clearly, was this: I wonder if BETWEEN tries to convert everything to the same type as its first operand? In other words, does “NUMBER BETWEEN DATE AND STRING” cast everything to a number? Is there an easy way to test this theory, or is it time to hit the source code?

I’m experimenting with queries like the following:

select '5e2' between 501 and date('2006-05-01');
select 500 between '5e2' and date('2006-05-01');

As far as I can tell, BETWEEN tries to convert all three operands to the type of the first operand. I have a feeling that the answer will clear everything up here.

]]>