Skip to content

Commit

Permalink
mysql-compatibility: add doc for a UPDATE incompatibility case (#7094)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao authored May 12, 2022
1 parent 0116a2c commit bebedf8
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions mysql-compatibility.md
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,10 @@ These differences are documented further in [`ANALYZE TABLE`](/sql-statements/sq

For details, see the [`SELECT`](/sql-statements/sql-statement-select.md) statement reference.

### `UPDATE` statement

See the [`UPDATE`](/sql-statements/sql-statement-update.md) statement reference.

### Views

Views in TiDB are not updatable. They do not support write operations such as `UPDATE`, `INSERT`, and `DELETE`.
Expand Down
12 changes: 11 additions & 1 deletion sql-statements/sql-statement-update.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,17 @@ mysql> SELECT * FROM t1;

## MySQL compatibility

This statement is understood to be fully compatible with MySQL. Any compatibility differences should be [reported via an issue](https://github.com/pingcap/tidb/issues/new/choose) on GitHub.
TiDB always uses the original value of a column when evaluating expressions. For example:

```sql
CREATE TABLE t (a int, b int);
INSERT INTO t VALUES (1,2);
UPDATE t SET a = a+1,b=a;
```

In MySQL, the column `b` is updated to 2 because it is set to the value of `a`, and the value of `a` (which is 1) is updated to `a+1` (which is 2) in the same statement.

TiDB follows the more standard SQL behavior, and updates `b` to 1.

## See also

Expand Down

0 comments on commit bebedf8

Please sign in to comment.