CREATE TABLE Language (
LanguageID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
LanguageName VARCHAR(40) NOT NULL,
PRIMARY KEY (LanguageID),
KEY LanguageName (LanguageName) )
ENGINE=MyISAM
DEFAULT CHARSET=utf8
COLLATE=utf8_unicode_ci;
INSERT INTO Language VALUES
(1, 'English'),
(2, 'Spanish'),
(3, 'American Sign Language'),
(4, 'Argentinian Sign Language');
-- works as expected - no collation - sorted by alias to a function result (alias has name matching a real field from a queried table)
SELECT LanguageID, substr(LanguageName, 2) as LanguageName
FROM Language
ORDER BY LanguageName;
-- broken - collated - sorted by alias to a function (coalesce) result (alias has name matching a real field from a queried table)
SELECT LanguageID, substr(LanguageName, 2) as LanguageName
FROM Language
ORDER BY LanguageName COLLATE utf8_spanish_ci;
-- broken - collated - sorted by alias to a column (alias has name matching a real field from a queried table)
SELECT LanguageID as LanguageName, substr(LanguageName, 2) as LanguageNameSubstr
FROM Language
ORDER BY LanguageName COLLATE utf8_spanish_ci;
Much shorter test case:
CREATE TABLE Language ( utf8_unicode_ ci;
LanguageID INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
LanguageName VARCHAR(40) NOT NULL,
PRIMARY KEY (LanguageID),
KEY LanguageName (LanguageName) )
ENGINE=MyISAM
DEFAULT CHARSET=utf8
COLLATE=
INSERT INTO Language VALUES
(1, 'English'),
(2, 'Spanish'),
(3, 'American Sign Language'),
(4, 'Argentinian Sign Language');
-- works as expected - no collation - sorted by alias to a function result (alias has name matching a real field from a queried table)
substr( LanguageName, 2) as LanguageName
SELECT LanguageID,
FROM Language
ORDER BY LanguageName;
-- broken - collated - sorted by alias to a function (coalesce) result (alias has name matching a real field from a queried table)
substr( LanguageName, 2) as LanguageName
SELECT LanguageID,
FROM Language
ORDER BY LanguageName COLLATE utf8_spanish_ci;
-- broken - collated - sorted by alias to a column (alias has name matching a real field from a queried table)
substr( LanguageName, 2) as LanguageNameSubstr
SELECT LanguageID as LanguageName,
FROM Language
ORDER BY LanguageName COLLATE utf8_spanish_ci;
drop table Language;