You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Postgres identifiers with double quotes not supported #1335
Describe the bug
Postgres supports double-quotes in table in column name identifiers with CSV-escape syntax, but they are unable to parse using JSqlParser
Parsing this SQL using JSqlParser with this statements
Exception
net.sf.jsqlparser.JSQLParserException: Encountered unexpected token: "\"quotes\"" <S_QUOTED_IDENTIFIER>
at line 1, column 26.
Was expecting one of:
"("
"SET"
"VALUES"
"WITH"
<K_SELECT>
at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatements(CCJSqlParserUtil.java:215)
at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatements(CCJSqlParserUtil.java:203)
Caused by: net.sf.jsqlparser.parser.ParseException: Encountered unexpected token: "\"quotes\"" <S_QUOTED_IDENTIFIER>
at line 1, column 26.
Was expecting one of:
"("
"SET"
"VALUES"
"WITH"
<K_SELECT>
at net.sf.jsqlparser.parser.CCJSqlParser.generateParseException(CCJSqlParser.java:26917)
at net.sf.jsqlparser.parser.CCJSqlParser.jj_consume_token(CCJSqlParser.java:26753)
at net.sf.jsqlparser.parser.CCJSqlParser.Insert(CCJSqlParser.java:2501)
at net.sf.jsqlparser.parser.CCJSqlParser.SingleStatement(CCJSqlParser.java:159)
at net.sf.jsqlparser.parser.CCJSqlParser.Statements(CCJSqlParser.java:547)
at net.sf.jsqlparser.parser.CCJSqlParserUtil.parseStatements(CCJSqlParserUtil.java:213)
... 26 more
Expected behavior
I expect JSqlParser to parse these statements and be able to process identifiers as unescaped ones.
unfortunately escaping/quoting is not very flexible in JSQLParser right now and this is unlikely to change soonest due to the nature of JavaCC and its way to define tokens.
Your best bet at the moment was to mangle your SQL with a Pre-processor, replacing your "" quotes with the JSQLParser compliant quotes and parse your statement.
The PostgreSQL double quote behavior follows SQL 1992 section 5 Lexical elements (presumably newer versions are the same). I do not know if the CSV usage predates that of SQL or vice versa.
Activity
manticore-projects commentedon Sep 9, 2021
Hi Anton,
unfortunately escaping/quoting is not very flexible in JSQLParser right now and this is unlikely to change soonest due to the nature of JavaCC and its way to define tokens.
Your best bet at the moment was to mangle your SQL with a Pre-processor, replacing your
""quotes with the JSQLParser compliant quotes and parse your statement.wumpz commentedon Sep 30, 2021
Or as always PRs are welcome or do you want to support in other ways?
sstock commentedon Feb 23, 2022
The PostgreSQL double quote behavior follows SQL 1992 section 5 Lexical elements (presumably newer versions are the same). I do not know if the CSV usage predates that of SQL or vice versa.
feat: Quoted Identifiers can contain double-quotes (PostgreSQL)
Assorted Fixes #8 (#1807)
Backslash Quotation of Single-Quote `'\\''` (#1813)