Skip to content

Recognise underscores and digits in PostgreSQL dollar-quote tags - #249

Merged
huandu merged 2 commits into
huandu:masterfrom
yuefdev:fix/postgres-dollar-quote-tags
Oct 23, 2026
Merged

huandu merged 2 commits into
huandu:masterfrom
yuefdev:fix/postgres-dollar-quote-tags

Conversation

@yuefdev

@yuefdev yuefdev commented Oct 18, 2026

Copy link
Copy Markdown
Contributor

PostgreSQL dollar-quote tags may start with an underscore and contain digits after the first character. The interpolator currently accepts only letters, so SELECT $tag_1$literal $2$tag_1$, $1 tries to bind the literal $2 and fails with a missing-argument error.

Recognise those tag characters while keeping a leading digit out of the tag. Tests preserve placeholders inside the literal and still bind the following $1; five tag cases fail before the fix. Empty and letter-only tags, Unicode letters and a digit-leading non-tag are also covered.

go test ./... -count=1, go vet ./... and formatting checks for the changed files pass. The tag rules are described in PostgreSQL's lexical syntax documentation.

Signed-off-by: Yusuf Efe <120668197+yuefdev@users.noreply.github.com>
@coveralls

coveralls commented Oct 20, 2026 •

Copy link
Copy Markdown

Coverage Status

coverage: 96.183% (+0.01%) from 96.17% — yuefdev:fix/postgres-dollar-quote-tags into huandu:master

@huandu huandu left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Requesting changes for one parser regression introduced by this change. The tag grammar itself is correct, and the reported cases now match PostgreSQL. However, the scanner still treats $ as a quote opener without checking the preceding token, which now also affects _-leading tags. There are two smaller cleanup suggestions as well. Details inline.

Comment thread interpolate.go Resolved
Comment thread interpolate.go Resolved
Comment thread interpolate_test.go Resolved
@huandu
huandu merged commit 9f157da into huandu:master Oct 23, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants