Question

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.

Was it helpful?

Solution

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

According to ANSI SQL, yes.

OTHER TIPS

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> ::=.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top