Skip to content

fix: reject multiple UPDATE assignments to the same column - #27100

Open
vshalpnjabi wants to merge 2 commits into
apache:mainfrom
vshalpnjabi:fix/update-duplicate-assignment-27096
Open

vshalpnjabi wants to merge 2 commits into
apache:mainfrom
vshalpnjabi:fix/update-duplicate-assignment-27096

Conversation

@vshalpnjabi

@vshalpnjabi vshalpnjabi commented Nov 4, 2026 •

Copy link
Copy Markdown

Which issue does this PR close?

Rationale for this change

UPDATE t SET a = 1, a = 2 planned successfully and applied only the last assignment. The SQL standard doesn't allow the same column twice in a SET list, and PostgreSQL and DuckDB reject it. A typo like SET a = x, a = y (meant b = y) would silently update the wrong data.

What changes are included in this PR?

SqlToRel::update_to_plan now inserts SET targets into the column map one at a time and returns a planning error on a repeat:

Error during planning: multiple assignments to same column "a"

t.a and a count as the same target, since the planner already keys SET columns by the last identifier.

Are these changes tested?

Yes:

  • update_rejects_duplicate_assignment in datafusion/sql/tests/sql_integration.rs (adjacent duplicates, a duplicate after another column, qualified + unqualified). It fails on main and passes with the fix.
  • update.slt: the issue's reproducer, plus a normal SET a = 1, b = 2 that still updates.

Ran locally:

  • cargo test -p datafusion-sql
  • cargo test --profile=ci -p datafusion-sqllogictest --test sqllogictests -- update.slt
  • cargo clippy -p datafusion-sql --all-targets --all-features -- -D warnings
  • cargo fmt --all -- --check

Are there any user-facing changes?

Yes. An UPDATE that assigns the same column more than once is now a planning error instead of keeping the last value. No public API changes.

One assumption to flag: the check compares the same key the planner already used (Ident.value, as written), so it doesn't add any identifier normalization of its own.

AI-assisted; I reviewed the full diff and ran the tests myself.

UPDATE t SET a = 1, a = 2 planned successfully and kept the last
assignment. Detect a duplicate SET target while building the
assignment map and return a planning error, matching PostgreSQL.

Closes apache#27096
@vshalpnjabi

Copy link
Copy Markdown
Author

@alamb Ready for review when you have a moment — thanks!

@github-actions github-actions Bot added sql SQL Planner sqllogictest SQL Logic Tests (.slt) labels Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

sql SQL Planner sqllogictest SQL Logic Tests (.slt)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

UPDATE accepts more than one assignment to the same column

1 participant