Skip to content

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

Merged
manticore-projects merged 2 commits into
JSQLParser:masterfrom
minleejae:fix/postgresql-tagged-dollar-strings
Sep 11, 2026
Merged

Support PostgreSQL tagged dollar strings and preserve literal bodies#2572
manticore-projects merged 2 commits into
JSQLParser:masterfrom
minleejae:fix/postgresql-tagged-dollar-strings

Conversation

@minleejae

@minleejae minleejae commented Sep 10, 2026

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 disabled by default to preserve identifier parsing. Enable it with withDialect(Dialect.POSTGRESQL) or withDollarQuotedStringTags(true); an explicit withDollarQuotedStringTags(false) after the PostgreSQL preset disables it again. 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, default/non-PostgreSQL identifier parsing, explicit opt-in and PostgreSQL preset overrides.
  • 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.

Comment thread src/main/java/net/sf/jsqlparser/parser/feature/Feature.java Outdated
@manticore-projects

Copy link
Copy Markdown
Contributor

고맙습니다!

@minleejae
minleejae force-pushed the fix/postgresql-tagged-dollar-strings branch from 06f7c8a to fd3779a Compare September 11, 2026 03:11
@manticore-projects
manticore-projects merged commit 8ff4f64 into JSQLParser:master Sep 11, 2026
3 of 4 checks passed
@manticore-projects

Copy link
Copy Markdown
Contributor

I miss my time in Seoul! I have been working for Woori Bank in 2009/10 and it was one of the best times of my life! You people are just amazing and your hospitality and sophistication is outstanding! Cheers my friend!

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