开发者

Interpreting SQL's BNF

开发者 https://www.devze.com 2023-01-21 07:09 出处:网络
I\'m looking at the syntax of SQL, specifically the character string literal. <character string literal> ::=

I'm looking at the syntax of SQL, specifically the character string literal.

<character string literal> ::=
    [ <introducer> <character set specification> ]
    <quote> [ <character representation> ... ] <quote>
    [ { <separator> <quote> [ <character representation> ... ] <quote> }... ]

Ignoring the [ <introducer> <character set specification> ] part, does this mean one or more <quote> [ <character representat开发者_StackOverflowion> ... ] <quote>s separated by a <separator>?

If so, does that mean that 'hello' 'world' should be parsed as one <character string literal>?

For the query SELECT 'hello' 'world', Microsoft SQL Server 2005 returns:

+-------+
| world |
+-------+
| hello |
+-------+

and MySQL 5.0 returns:

+------------+
| hello      |
+------------+
| helloworld |
+------------+

I understand that every flavor of SQL is different, and that they don't all follow the standard. I'm just trying to determine whether I'm interpreting the BNF correctly. Thanks.


If so, does that mean that 'hello' 'world' should be parsed as one ?

According to ANSI SQL, yes.


To clarify what is happening in SQL Server, what you're actually doing is returning 'hello' with a column name of 'world'. Your example is the same as:

SELECT 'hello' AS 'world'

If you tried to extend your thought further, you'd get an error:

SELECT 'hello' 'world' 'now'

Line 1: Incorrect syntax near 'now'.


Look at the BNF for <separator> ::=.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号