Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Escape character + escaped double quote makes formatted SQL invalid #61

Open
jzillmann opened this issue Oct 13, 2022 · 2 comments
Open

Comments

@jzillmann
Copy link

In Postgres such a query is valid:

select A as "A\""B" from "T1";

The single result column will be named A\"B.
The backslash escape isn't used as escape here, the first inner " will escape the following ".
To demonstrate the logic a bit more a few examples:

  • A\B => A\B
  • A""B => A"B

Now the formatter chokes on this.

select A as "A\""B" from "T1";

will be formatted as

select A as "A\"" B " from " T1 ";

Which is not even executable anymore.
Is there any configuration that could alleviate this problem ?

@manticore-projects
Copy link

Greetings.

With JSQLParser, your query parses just fine

SQL Text
 └─Statements: statement.select.PlainSelect
    ├─selectItems: statement.select.SelectItem
    │  ├─Column: a
    │  └─Alias:  AS "A\""B"
    └─Table: "T1"

@vertical-blank you may have a look at the Tokens

  1. S_CHAR_LITERAL at https://github.com/manticore-projects/JSqlParser/blob/5e7732c870a66afff5b39214b2cfbb0409e12585/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt#L531

  2. or S_QUOTED_IDENTIFIER at https://github.com/manticore-projects/JSqlParser/blob/5e7732c870a66afff5b39214b2cfbb0409e12585/src/main/jjtree/net/sf/jsqlparser/parser/JSqlParserCC.jjt#LL557C5-L557C24

for more complete Regular Expressions. It should be a copy'n paste option.

@philos1234
Copy link

is there any update on this issue?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants