Skip to content

Support PostgreSQL tagged dollar strings and preserve literal bodies - #2572

Open
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:fix/postgresql-tagged-dollar-strings
Open

Support PostgreSQL tagged dollar strings and preserve literal bodies#2572
minleejae wants to merge 1 commit into
JSQLParser:masterfrom
minleejae:fix/postgresql-tagged-dollar-strings

Conversation

@minleejae

Copy link
Copy Markdown
Contributor

Tagged PostgreSQL strings such as $json$…$json$ currently fail to parse or become column references. Recognize them as StringValue while preserving the exact delimiter, whitespace and literal contents:

SELECT $json$[{"some":"json","with":"properties$"}]$json$::jsonb;

Reuse a shared delimiter recognizer in the lexer, StringValue and routine-body boundary detection. The lexer reads the original character stream with a linear delimiter matcher, handles longest-match identifier tokens, and updates token end positions. Dollar-quoted values keep doubled apostrophes unchanged in getNotExcapedValue(). A tagged routine body remains one token, so a following SQL statement is preserved.

Tagged quoting is enabled by default. For dialects that use the same spelling as an unquoted identifier, withDollarQuotedStringTags(false) preserves the previous identifier interpretation; ordinary dollar-containing identifiers, positional parameters and untagged $$ literals remain supported.

Validation:

  • Full Gradle check and Maven verify.
  • Re-enabled the existing tagged-string regression test.
  • Empty/Unicode tags, whitespace and CRLF preservation, embedded dollar signs and other tags, casts, bind parameters, quoted identifiers and the compatibility option.
  • Model/deparser round-trips, token positions, long Reader/InputStream inputs with overlapping delimiter prefixes, unterminated tags, and routine bodies followed by another statement.
  • Syntax follows the PostgreSQL dollar-quoting documentation.

Fixes #2233.

@manticore-projects manticore-projects left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good work, just minor German nit picking.

* Recognizes PostgreSQL $tag$...$tag$ literals. Disable for dialects where these spellings are
* unquoted identifiers. Untagged $$ literals are unaffected.
*/
allowDollarQuotedStringTags(true),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Question: would we not expected false here until Dialect=Postgres is set?

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

Successfully merging this pull request may close these issues.

[BUG] JSQLParser 5.1: PostgreSQL: fail to parse dollar-quoted string constants with tags

2 participants