views:

90

answers:

3

Checking few RDBMS I find that things like

SELECT COUNT (a), SUM (b)  
FROM TABLE

are allowed (notice space between aggregate functions and parenthesis).

Could anyone provide a pointer to SQL standard itself where this is defined (any version will do)?

EDIT: The above works in postgres, mysql needs set sql_mode = "IGNORE_SPACE"; as defined here (for full list of functions that are influenced with this server mode see in this ref). MS SQL is reported to accept the above.

Also, it seems that the answer is most likely in the standard. I can follow the BNF regarding the regular symbols and terms, but I get lost when it comes to the definition of whitespace and separators in that part of the select.

A: 

I can't provide a pointer, but I believe that white space like that is ignored.

I know that it is in T-SQL, and about 80% certain about MySQL's implementation.

Stephen Wrighton
+1  A: 

Yes; the white space between tokens is substantially ignored. The only exception is, officially, with adjacent string literal concatenation - but the standard is weirder than any implementation would be.

See: http://savage.net.au/SQL/

Jonathan Leffler
Thanks for the link to the standards. Looking at the grammar if I can work it out.
Unreason
A: 

This works in SQL Server 2005:

SELECT COUNT   (*)
  FROM TABLE

...while one space between COUNT and (*) on MySQL causes a MySQL 1064 error (syntax error). I don't have Oracle or Postgres handy to test.

Whatever the standard may be, it's dependent on implementation in the vendor and version you are using.

OMG Ponies
actually it will work in mysql as well if you set sql_mode = "IGNORE_SPACE"; (which IMHO tries to bring it closer to standard)
Unreason