Search code examples
sqlsyntaxbnf

Interpreting SQL's BNF


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 representation> ... ] <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.


Solution

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

    According to ANSI SQL, yes.