fix: handle named params in SQLite upsert ON CONFLICT DO UPDATE SET#4411
Open
Bhagwat-45 wants to merge 1 commit intosqlc-dev:mainfrom
Open
fix: handle named params in SQLite upsert ON CONFLICT DO UPDATE SET#4411Bhagwat-45 wants to merge 1 commit intosqlc-dev:mainfrom
Bhagwat-45 wants to merge 1 commit intosqlc-dev:mainfrom
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When using
@param,sqlc.arg(), orsqlc.narg()in theON CONFLICT DO UPDATE SETclause of a SQLite upsert, sqlc leavesthe raw parameter references unrewritten in the generated SQL instead
of replacing them with
?Nplaceholders.Root Cause
convertInsert_stmtContextnever calledn.Upsert_clause(), so theOnConflictClausefield was always nil and params inside it werenever processed by the rewriter.
Fix
Added
convertUpsert_clauseContextthat properly builds theOnConflictClauseAST node with infer clause, target list, andwhere clause — calling
c.convert()on all expressions so namedparams are correctly rewritten.
Test
Added end-to-end test
upsert_named_params/sqlitereproducing theexact query from the issue.
Fixes #3508