A new MySQL gotcha

At least it's new for me, and it's not on the list. Bugged a colleague of mine today, and we were both very surprised for a while until we figured it out. Ok, it's not very complex, but the deal was that:

SELECT CAST(1 as CHAR)

works, but

SELECT CAST (1 as CHAR)

does not (syntax error!)

Now, CAST is already horribly limited in MySQL (who came up with the idea that you shouldn't be able to cast to all available types if it's reasonable to do the conversion?! Like from int to text...), but this is just too much. Since when does whitespace before a parenthesis matter in SQL?! Sheesh...

Yet another reason to prefer PostgreSQL...


Comments

Whitespace before parenthesis shouldn't matter, but MySQL allows reserved words to be table and field names, and the way it does that is by requiring no white space between the function name and its opening left paren.

Posted on Apr 1, 2010 at 00:46 by Joshua Kugler.

Add comment

New comments can no longer be posted on this entry.

Conferences

I speak at and organize conferences around Open Source in general and PostgreSQL in particular.

Upcoming

PGConf.EU 2026
Oct 20-23, 2026
Valencia, Spain
FOSDEM PGDay 2027
Jan 28-31, 2027
Brussels, Belgium
Nordic PGDay 2027
Mar 16, 2027
Stockholm, Sweden

Past

PGDay Lowlands 2026
Sep 10, 2026
Utrecht, Netherlands
PGDay.UK 2026
Sep 8, 2026
London, UK
pgconf.dev 2026
May 19-22, 2026
Vancouver, Canada
pgDay.paris 2026
Mar 26, 2026
Paris, France
Nordic PGDay 2026
Mar 24, 2026
Helsinki, Finland
More past conferences