I'm in the process of upgrading our in-house applications from MySQL 5.0.45 to 5.1.41. In the old environment we had mirrored some tables using symlinks from one DB to another. For a few reasons, current versions of MySQL block that completely.
What seemed like the best replacement was using a view instead, but I'm having a problem. A few old tables have column names that are capitalized. However some of our application code (PHP) does a SELECT with the capitalized name and also some SELECTs with lower case column names. Which normally works fine because MySQL returns tables with a column name capitalized as you referenced it in the SELECT. However, with a view that doesn't seem to be the case. See the following:
create table t(A int);
Query OK, 0 rows affected (0.18 sec)
> create view v as select A from t;
Query OK, 0 rows affected (0.00 sec)
> insert into t values(47);
Query OK, 1 row affected (0.01 sec)
> select a from t;
+------+
| a |
+------+
| 47 |
+------+
1 row in set (0.00 sec)
> select a from v;
+------+
| A |
+------+
| 47 |
+------+
1 row in set (0.00 sec)
Notice that the capitalization of the column name returned in the SELECT queries is different whether or not you select from the table or the view. The table returns the capitalization as specified in your query at runtime; the view returns the capitalization when the view was created. This seems to be consistent through both versions of MySQL, both the command-line client and through the PHP library client.
One trick I discovered is that if you add a GROUP BY to the SELECT in the view it will use the capitalization in your query at runtime. Unfortunately that breaks updating through the view, which I need.
Is there any way to make the column name capitalization match the query at runtime, which doesn't involve going back and changing all of our application code?
SELECT a AS fiElD_NaMe FROM v;
– Kaliope