Does SQL standard allows whitespace between functi

2019-06-25 13:19发布

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.

3条回答
欢心
2楼-- · 2019-06-25 13:55

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.

查看更多
【Aperson】
3楼-- · 2019-06-25 14:03

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/

查看更多
地球回转人心会变
4楼-- · 2019-06-25 14:08

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.

查看更多
登录 后发表回答