JSQLParser / JSqlParser

JSqlParser parses an SQL statement and translate it into a hierarchy of Java classes. The generated hierarchy can be navigated using the Visitor Pattern
https://github.com/JSQLParser/JSqlParser/wiki
Apache License 2.0
5.33k stars 1.34k forks source link

Quoted aliases (with spaces) #168

Closed tbrielle closed 9 years ago

tbrielle commented 9 years ago

Tested with JSQLParser 0.9.3 (and JSQLParser 0.9.4-SNAPSHOT at date of writing)

The following queries are valid in MSSQL :

    select top 10 mycolumn as [xxx yyy] from mytable;
    select top 10 mycolumn as 'xxx yyy' from mytable;

However the parsing of the last one fails with the exception:

net.sf.jsqlparser.parser.ParseException: Encountered " <S_CHAR_LITERAL> "\'xxx yyy\' "" at line 1, column 27.
wumpz commented 9 years ago

That is right. Your SQL is not valid. Databaseobject names or aliases are not quoted using single quotation marks. Or is there a database that supports this? JSqlParser supports [colname], "colname", and colname (apostroph used by MSAccess).

tbrielle commented 9 years ago

It seems to be supported in TSQL

wumpz commented 9 years ago

Agreed. Never saw that before, but it is very non standard und a deprecated feature:

https://msdn.microsoft.com/en-us/library/bb510662%28v=sql.110%29.aspx "String literals as column aliases"

Additional you could create so much confusion.

select 'test' from mytable

Is test a column or a string literal.

JSqlParser will not support this.

Tobias

tbrielle commented 9 years ago

OK. Thank you.

wumpz commented 6 years ago

solved #583