Bug #27249 table_wild with alias: select t1.* as something
Submitted: 18 Mar 2007 17:45 Modified: 24 Oct 2007 20:52
Reporter: Martin Friebe (Gold Quality Contributor) (SCA)
Status: Closed
Category:Server: Parser Severity:S4 (Feature request)
Version:5.0.38 4.1.23 OS:Any (*)
Assigned to: Davi Arnaut Target Version:
Tags: wildcard, alias, Contribution
Triage: D5 (Feature request)

[18 Mar 2007 17:45] Martin Friebe
Description:
you can specify an alias for a table_willcard:

 select t1.* as 'foo' from t1;

It is ignored, but it should not be allowed. the following seems to be from sql99 (and is
the only thing I could find) / not verified

-- qoute
<select list> ::= <asterisk> | <select sublist> [{<comma> <select sublist>}...]

<select sublist> ::= <derived column> | <qualified asterisk>

<derived column> ::= <value expression> [ <as clause> ]

<qualified asterisk> ::=
		<asterisked identifier chain> <period> <asterisk>
	|	<all fields reference> 
-- end quote

but according to this the qualified asterisk, should not have an alias

How to repeat:
drop table if exists t1;
create table t1 (a int);

select t1.* as 'foo' from t1;

Suggested fix:
see patch (includes patch to existing alias test)
[18 Mar 2007 17:45] Martin Friebe
patch and test

Attachment: table_wild.patch (text/x-patch), 4.27 KiB.

[18 Mar 2007 18:10] Valeriy Kravchuk
Thank you for a bug report and patch. Bug verified just as described, also - with 5.0.37.

Draft version of SQL:2003 standard has the same definishion of <qualified asterisk> as you
quoted.
[21 Mar 2007 18:43] Peter Gulutzan
Since MySQL's behaviour doesn't actually contradict the documentation
(the reference manual is silent), I mark this as a feature request.

That does not affect whether a patch can go in the community tree, though.
[24 Mar 2007 16:57] Martin Friebe
corrected spaces, added tests

Attachment: table_wild.patch (text/x-patch), 18.65 KiB.

[6 Sep 2007 18:49] Konstantin Osipov
5.2 only.
[8 Oct 2007 13:48] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/35093

ChangeSet@1.2610, 2007-10-08 08:47:51-03:00, davi@moksha.local +3 -0
  Bug#27249 table_wild with alias: select t1.* as something
  
  Aliases to table wildcards are silently ignored, but they should
  not be allowed as it is non-standard and currently useless. There
  is not point in having a alias to a wildcard of column names.
  
  The solution is to rewrite the select_item rule so that aliases
  for table wildcards are not accepted.
  
  Contribution by Martin Friebe
[10 Oct 2007 1:31] Marc Alff
This report could be arguably qualified either

- as a feature / not a bug:
MySQL has the right to support non standard extensions,
like "select t1.* as alias"

- as a bug:
Clearly this was not intended, has no meaning,
and is an "accidental" syntax allowed

Considering that the said syntax has no harmful effect (the alias is ignored)
in 5.1 or earlier, this fix will go into the 5.2 code base only.

The technical change itself is trivial and low risk,
and could be back ported any time (but there is no real need for it).

Thanks to Martin Friebe for spotting this, and for the solution.
[19 Oct 2007 21:25] Marc Alff
Pushed in 5.2.6
[24 Oct 2007 20:52] Paul DuBois
Noted in 5.2.6 changelog.

Aliases for wildcards (as in SELECT t.* AS 'alias' FROM t) are no
longer accepted and result in an error. Previously, such aliases were
ignored silently.
[29 Oct 2007 18:36] Paul DuBois
5.2.6 changes will appear in 6.0.3 instead.