kumarUjjawal opened a new issue, #27096:
URL: https://github.com/apache/datafusion/issues/27096

   ### Describe the bug
   
   `UPDATE` accepts more than one assignment to the same column. The last 
assignment wins, and the earlier ones are silently dropped.
   
   The SQL standard does not allow the same column more than once in a `SET` 
list. PostgreSQL and DuckDB reject the statement.
   
   ### To Reproduce
   
   ```sql
   CREATE TABLE t (a INT, b INT) AS VALUES (0, 0);
   UPDATE t SET a = 1, a = 2;
   SELECT * FROM t;
   UPDATE t SET a = 3, b = 4, a = 5;
   SELECT * FROM t;
   ```
   
   On main (`c120619de`), both `UPDATE` statements succeed:
   
   ```text
   +---+---+
   | a | b |
   +---+---+
   | 2 | 0 |
   +---+---+
   +---+---+
   | a | b |
   +---+---+
   | 5 | 4 |
   +---+---+
   ```
   
   ### Expected behavior
   
   A planning error, as in other engines:
   
   * PostgreSQL 17: `ERROR: multiple assignments to same column "a"`
   * DuckDB: `Binder Error: Multiple assignments to same column "a"`
   
   ### Additional context
   
   `SqlToRel::update_to_plan` in `datafusion/sql/src/statement.rs` collects the 
assignments into a `HashMap<String, SQLExpr>`. A duplicate column name 
overwrites the earlier entry with no error. A check for a duplicate key before 
the insert would reject the statement.
   
   A typo such as `SET a = x, a = y` (instead of `SET a = x, b = y`) now 
changes the wrong data with no warning.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to