Bug #10239 Views don't allow column aliases
Submitted: 28 Apr 2005 18:05 Modified: 1 May 2005 7:08
Reporter: leeann pultz Email Updates:
Status: Can't repeat Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:5 beta OS:Windows (Windows (all?))
Assigned to: CPU Architecture:Any

[28 Apr 2005 18:05] leeann pultz
Description:
Hi 

I would like to know whether the final version of mysql 5 will allow column aliases when selecting from views? Or possibly I'm doing this wrong :) 

Currently, I have a view called "problem" with columns id, short_descr, status etc. 

When I write a query against the view, like: 

select id, short_descr title, status 
from problem; 

I get back results with column headers: id, short_descr, status 

when I do the same query against a table with the same columns, the alias works. 

Anyone know whether this is a bug or simply a feature that has not yet been implemented in views, and whether there are plans to implement it? 

thanks very much! 

LeeAnn

How to repeat:
create a view.

do a select from the view, using the column names set up in the view. this works.

do a select from the view, using a column alias on one of the columns.  the results use the column name, not the alias, as the column header.

Suggested fix:
The results should show the column alias as the header for the column, if specified in the query.
[1 May 2005 7:08] Jorge del Conde
I was unable to reproduce this in 5.0.5 from bk:

mysql> SELECT * FROM tmp;
+------+------+
| id   | str  |
+------+------+
|    1 | '    |
|    1 | ''   |
|    1 | '''  |
|    1 | '''' |
+------+------+
4 rows in set (0.00 sec)

mysql> CREATE VIEW tmp_view AS SELECT id as id_alias, str as str_alias, id, str FROM tmp;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT * FROM tmp_view;
+----------+-----------+------+------+
| id_alias | str_alias | id   | str  |
+----------+-----------+------+------+
|        1 | '         |    1 | '    |
|        1 | ''        |    1 | ''   |
|        1 | '''       |    1 | '''  |
|        1 | ''''      |    1 | '''' |
+----------+-----------+------+------+
4 rows in set (0.00 sec)
[6 May 2005 18:38] leeann pultz
Ah! I was unclear:

I was unable to reproduce this in 5.0.5 from bk:

mysql> SELECT id id_alias, str str_alias FROM tmp;
+------+------+
| id_alias   | str_alias  |
+------+------+
|    1 | '     |
|    1 | ''    |
|    1 | '''   |
|    1 | ''''  |
+------+------+
4 rows in set (0.00 sec)

mysql> CREATE VIEW tmp_view AS SELECT id, str
FROM tmp;
Query OK, 0 rows affected (0.00 sec)

mysql> SELECT id id_alias, str str_alias FROM tmp_view;
+----------+-
| id   | str  |
+----------+
|        1 | '         |
|        1 | ''        | 
|        1 | '''       |
|        1 | ''''      |
+----------+-----------+------+------+
4 rows in set (0.00 sec)