Skip to content

Fix placeholder numbering in UPDATE SET subqueries - #405

Open
skyon0522-ai wants to merge 1 commit into
Masterminds:masterfrom
skyon0522-ai:fix-update-set-subquery-placeholders-326
Open

skyon0522-ai wants to merge 1 commit into
Masterminds:masterfrom
skyon0522-ai:fix-update-set-subquery-placeholders-326

Conversation

@skyon0522-ai

Copy link
Copy Markdown

When a shared Dollar-formatted StatementBuilder builds both an UPDATE and its SET subquery, the subquery replaces its placeholders before the outer UPDATE does. The inner and outer WHERE clauses can therefore both use $1, despite returning separate arguments.

Use the existing nestedToSql helper for SET values, as for other nested query parts, so the outer statement applies its placeholder format. Keep the existing SELECT parentheses and generic Sqlizer fallback.

Fixes #326.

Validation on Go 1.27.2 / Linux amd64:

  • Reproduced the reported query before the change: Dollar numbering collides; the Question-format control passes.
  • The regression adds a preceding SET argument and distinct values to check numbering offsets and argument order. Before the change, Dollar, Colon and AtP fail while Question passes; all four pass after the change.
  • go test -count=1 ./... and go vet ./... pass.
  • gofmt -l update.go update_test.go and git diff --check are clean.

Validation covers generated SQL and arguments; no live database integration or other Go version was tested.

This change was prepared with AI assistance.

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.

UpdateBuilder.Set with subquery produces wrong dollar parameter placeholders

1 participant