MySQL view column name capitalization MySQL view column name capitalization php php

MySQL view column name capitalization


I have to say I'm not 100 % sure, but I strongly suspect you can't get a matching case in your views without modifying the application code. Have a look at how the view is defined (I'm using MySQL 5.1.56):

mysql> show create view v;+------+-----------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+| View | Create View                                                                                                           | character_set_client | collation_connection |+------+-----------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+| v    | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v` AS select `t`.`A` AS `A` from `t` | utf8                 | utf8_general_ci      |+------+-----------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+1 row in set (0.00 sec)

As you can see, MySQL adds a column alias (AS), and AFAIK there's no way to make it behave differently. Defining a column name explicitly has the same result:

mysql> create view v2 (viewa) as select A from t;Query OK, 0 rows affected (0.02 sec)mysql> select Viewa from v2;+-------+| viewa |+-------+|    47 |+-------+1 row in set (0.00 sec)mysql> show create view v2;+------+----------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+| View | Create View                                                                                                                | character_set_client | collation_connection |+------+----------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+| v2   | CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v2` AS select `t`.`A` AS `viewa` from `t` | utf8                 | utf8_general_ci      |+------+----------------------------------------------------------------------------------------------------------------------------+----------------------+----------------------+1 row in set (0.00 sec)

Adding a (somewhat funny-looking) column alias in all your SQL queries would obviously fix the issue:

mysql> select a as a from v;+------+| a    |+------+|   47 |+------+1 row in set (0.00 sec)


instead of,

    mysql> select a from v;

use this (with an alias),

    mysql> select a as a from v;    +------+    | a    |    +------+    |   47 |    +------+    1 row in set (0.00 sec)