Bug #1685 Error while parsing fields in the SELECT part of a statement
Submitted: 28 Oct 2003 0:44 Modified: 28 Oct 2003 4:28
Reporter: yk Email Updates:
Status: Not a Bug Impact on me:
None 
Category:MySQL Server Severity:S2 (Serious)
Version:4.0.15-standard OS:Linux (linux rh9)
Assigned to: CPU Architecture:Any

[28 Oct 2003 0:44] yk
Description:
A missing comma in the field list in a select statement does not generate an error. The query goes through and only the first field i sent back to the client.

How to repeat:
Run the statements below in the same session. The missing character, which I think should result in a parse error, is between the first two fields in the SELECT part:

CREATE TABLE `exportFarsDag2003KontrollTest` (
  `poängkonto` int(9) unsigned NOT NULL default '0',
  `namn` char(32) NOT NULL default '',
  `gatuadress` char(32) NOT NULL default '',
  `postnummer` mediumint(5) unsigned zerofill NOT NULL default '00000',
  `postadress` char(25) NOT NULL default '',
  `typ` char(30) NOT NULL default '',
  `kundnr` mediumint(7) unsigned NOT NULL default '0',
  `kön` char(1) NOT NULL default '',
  `kontrollgrupp` char(1) NOT NULL default ''
) TYPE=MyISAM;

CREATE TABLE xxx
      SELECT
        poängkonto
        namn,
        gatuadress,
        postnummer,
        postadress,
        typ,
        kundnr,
        kön,
        kontrollgrupp
      FROM
        test.exportFarsDag2003KontrollTest u
      WHERE
        u.kontrollGrupp = 'xxx';

Suggested fix:
Ahem, MS-SQL anyone?  ;^)
[28 Oct 2003 4:28] Georg Richter
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.mysql.com/documentation/ and the instructions on
how to report a bug at http://bugs.mysql.com/how-to-report.php
[28 Oct 2003 4:32] Georg Richter
From http://www.mysql.com/doc/en/SELECT.html 
 
A SELECT expression may be given an alias using AS alias_name. The alias is used as the 
expression's column name and can be used with ORDER BY or HAVING clauses. For 
example:  
mysql> SELECT CONCAT(last_name,', ',first_name) AS full_name 
    FROM mytable ORDER BY full_name; 
 
 The AS keyword is optional when aliasing a SELECT expression. The preceding example 
could have been written like this:  
mysql> SELECT CONCAT(last_name,', ',first_name) full_name 
    FROM mytable ORDER BY full_name; 
 
In your sample "namn" will be used as an alias for field "poängkonto"