tags:

views:

40

answers:

3

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.

A: 

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'.
Joe Stefanelli
@Joe. Thanks, I actually understood that from the beginning. My main question is regarding the BNF.
Jordan
A: 

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

Brent Arias
and then what? I can't see how this helps.
gbn
@Mystagogue. I interpret it as one or more <comment>s or <whitespace>s.
Jordan
+1  A: 

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

According to ANSI SQL, yes.

500 - Internal Server Error
@500. Thank you.
Jordan