Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support MySQL 8.0.19 feature - aliases in the values and the set clause of insert into ... on duplicate key update #51650

Open
yahonda opened this issue Mar 11, 2024 · 0 comments
Labels
compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) type/compatibility type/feature-request Categorizes issue or PR as related to a new feature.

Comments

@yahonda
Copy link
Member

yahonda commented Mar 11, 2024

Feature Request

I want TiDB supports one of the MySQL 8.0.19 new feature, aliases in the values and the set clause of insert into ... on duplicate key update. Not only adding as a new feature MySQL 8.0.20 deprecates the "old" syntax.

MySQL now supports aliases in the VALUES and SET clauses of INSERT INTO ... ON DUPLICATE KEY UPDATE statement
for the row to be inserted and its columns. Consider a statement such as this one:

https://dev.mysql.com/worklog/task/?id=6312
mysql/mysql-server@c39355e

  • MySQL 8.0.20 deprecates the old VALUES() syntax in INSERT ... ON DUPLICATE KEY UPDATE statements

https://dev.mysql.com/doc/relnotes/mysql/8.0/en/news-8-0-20.html

The use of VALUES() to access new row values in INSERT ... ON DUPLICATE KEY UPDATE statements
is now deprecated, and is subject to removal in a future MySQL release.
Instead, you should use aliases for the new row and its columns as implemented in MySQL 8.0.19 and later.

https://dev.mysql.com/worklog/task/?id=13325
mysql/mysql-server@6f3b9df

Describe the feature you'd like:
Support aliases in the values and the set clause of insert into ... on duplicate key update.

  • MySQL 8.0.20 and newer versions of MySQL supports aliases in the values insert into ... on duplicate key update.
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.3.0     |
+-----------+
1 row in set (0.00 sec)
mysql> use test;
Database changed
mysql> CREATE TABLE t1
    -> (col1 integer primary key,
    -> col2 integer
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> INSERT INTO t1 values(1,1);
Query OK, 1 row affected (0.00 sec)

mysql>
mysql> INSERT INTO t1(col1, col2)
    ->   VALUES (1, 2) AS new(col1, new2)
    ->   ON DUPLICATE KEY UPDATE col1 = new.col1 + new2;
Query OK, 2 rows affected (0.00 sec)

mysql>
mysql> select * from t1;
+------+------+
| col1 | col2 |
+------+------+
|    3 |    1 |
+------+------+
1 row in set (0.00 sec)
  • MySQL 8.0.20 and newer versions of MySQL raises the warnings for "old" syntax.
mysql> select version();
+-----------+
| version() |
+-----------+
| 8.3.0     |
+-----------+
1 row in set (0.00 sec)
mysql> CREATE TABLE t
    -> (
    -> a integer primary key,
    -> b integer
    -> );
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql>
mysql> INSERT INTO t
    ->     VALUES (9,5), (7,7), (11,-1)
    ->     ON DUPLICATE KEY UPDATE a = a + VALUES(a) - VALUES(b);
Query OK, 3 rows affected, 2 warnings (0.01 sec)
Records: 3  Duplicates: 0  Warnings: 2

mysql> show warnings;
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                                                                                                   |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1287 | 'VALUES function' is deprecated and will be removed in a future release. Please use an alias (INSERT INTO ... VALUES (...) AS alias) and replace VALUES(col) in the ON DUPLICATE KEY UPDATE clause with alias.col instead |
| Warning | 1287 | 'VALUES function' is deprecated and will be removed in a future release. Please use an alias (INSERT INTO ... VALUES (...) AS alias) and replace VALUES(col) in the ON DUPLICATE KEY UPDATE clause with alias.col instead |
+---------+------+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
2 rows in set (0.00 sec)

Describe alternatives you've considered:
Use the "old" syntax.

Teachability, Documentation, Adoption, Migration Strategy:

@yahonda yahonda added the type/feature-request Categorizes issue or PR as related to a new feature. label Mar 11, 2024
@dveeden dveeden mentioned this issue Mar 18, 2024
70 tasks
@dveeden dveeden added type/compatibility compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) labels Mar 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compatibility-mysql8 This is a compatibility issue with MySQL 8.0(but NOT 5.7) type/compatibility type/feature-request Categorizes issue or PR as related to a new feature.
Projects
None yet
Development

No branches or pull requests

2 participants