Skip to content

fix: handle named params in SQLite upsert ON CONFLICT DO UPDATE SET#4411

Open
Bhagwat-45 wants to merge 1 commit intosqlc-dev:mainfrom
Bhagwat-45:fix/3508-sqlite-upsert-arg-narg
Open

fix: handle named params in SQLite upsert ON CONFLICT DO UPDATE SET#4411
Bhagwat-45 wants to merge 1 commit intosqlc-dev:mainfrom
Bhagwat-45:fix/3508-sqlite-upsert-arg-narg

Conversation

@Bhagwat-45
Copy link
Copy Markdown

Problem

When using @param, sqlc.arg(), or sqlc.narg() in the
ON CONFLICT DO UPDATE SET clause of a SQLite upsert, sqlc leaves
the raw parameter references unrewritten in the generated SQL instead
of replacing them with ?N placeholders.

Root Cause

convertInsert_stmtContext never called n.Upsert_clause(), so the
OnConflictClause field was always nil and params inside it were
never processed by the rewriter.

Fix

Added convertUpsert_clauseContext that properly builds the
OnConflictClause AST node with infer clause, target list, and
where clause — calling c.convert() on all expressions so named
params are correctly rewritten.

Test

Added end-to-end test upsert_named_params/sqlite reproducing the
exact query from the issue.

Fixes #3508

The convertInsert_stmtContext function was not converting the upsert
clause, leaving @param and sqlc.arg()/sqlc.narg() references unrewritten
in ON CONFLICT DO UPDATE SET assignments.

Add convertUpsert_clauseContext to properly build the OnConflictClause
AST node, including:
- Infer clause from ON CONFLICT (col, ...) target columns
- TargetList with properly converted param expressions
- Optional WHERE clause support
- DO NOTHING support

Fixes sqlc-dev#3508
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.

upsert with arg or narg doesn't work in sqlite3

1 participant