The following test case describes my problem.
CREATE TABLE the_table (id INT, Title CHAR(10));
CREATE VIEW the_view AS SELECT * FROM the_table;
INSERT INTO the_table VALUES (1, 'Hello');
notice that ‘Title’ in capitalized
Now when I try:
SELECT id, title FROM the_table;
Result:
+------+-------+
| id | title |
+------+-------+
| 1 | Hello |
+------+-------+
(notice how ‘title’ is lowercase in both the query and the result column)
BUT, when i do the same thing on the view:
SELECT id, title FROM the_view;
Result:
+------+-------+
| id | Title |
+------+-------+
| 1 | Hello |
+------+-------+
It is the same select clause, but this time the column name for ‘Title’ is Capitalized!
I am trying to reuse a code with a view of the exact same schema, but this messes it up.
I can’t really find any reference whether this is standard MySQL behavior or not, but is there a way around it?
If we query how the view is stored:
… we find a result that contains this:
This happens as well if you replace
*with a column list: MySQL adds anASclause with an alias, which effectively hard-codes column names.The conclusion is that a view is not a table. You’ll need to create it with the exact case you want to use. Whatever, case is normally irrelevant unless your client language messes things up when case changes (e.g. PHP associative arrays).