-
-
Notifications
You must be signed in to change notification settings - Fork 2k
MDEV-29919: Support INSERT ... AS alias ON DUPLICATE KEY UPDATE #4544
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
Open
MooSayed1
wants to merge
1
commit into
MariaDB:main
Choose a base branch
from
MooSayed1:MDEV-29919-insert-as-alias
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+247
−1
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| # | ||
| # MDEV-29919: Support INSERT ... VALUES AS alias ON DUPLICATE KEY UPDATE | ||
| # | ||
| # | ||
| # Test setup | ||
| # | ||
| CREATE TABLE t1 ( | ||
| a INT PRIMARY KEY, | ||
| b INT, | ||
| c INT | ||
| ); | ||
| # | ||
| # Basic INSERT AS alias ON DUPLICATE KEY UPDATE | ||
| # | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b, c = new.c; | ||
| SELECT * FROM t1; | ||
| a b c | ||
| 1 20 200 | ||
| # | ||
| # Multiple rows with AS alias | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200), (2, 30, 300) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b; | ||
| SELECT * FROM t1 ORDER BY a; | ||
| a b c | ||
| 1 20 100 | ||
| 2 30 300 | ||
| # | ||
| # Expression using alias columns | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 5, 50) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b + new.c, c = new.a * 10; | ||
| SELECT * FROM t1; | ||
| a b c | ||
| 1 55 10 | ||
| # | ||
| # Mix of alias and table column references | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b, c = t1.c + new.c; | ||
| SELECT * FROM t1; | ||
| a b c | ||
| 1 20 300 | ||
| # | ||
| # INSERT without ON DUPLICATE KEY (alias should be ignored) | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100) AS new; | ||
| SELECT * FROM t1; | ||
| a b c | ||
| 1 10 100 | ||
| # | ||
| # Different alias names | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 99, 999) AS inserted_row | ||
| ON DUPLICATE KEY UPDATE b = inserted_row.b, c = inserted_row.c; | ||
| SELECT * FROM t1; | ||
| a b c | ||
| 1 99 999 | ||
| # | ||
| # Alias cannot be the same as the target table name | ||
| # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 50, 500) AS t1 | ||
| ON DUPLICATE KEY UPDATE b = t1.b; | ||
| ERROR 42000: Not unique table/alias: 't1' | ||
| # | ||
| # Verify that AS alias is NOT allowed in REPLACE | ||
| # | ||
| REPLACE INTO t1 VALUES (1, 50, 500) AS new; | ||
| ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use | ||
| # | ||
| # Verify that AS alias is NOT allowed in CREATE ... VALUES | ||
| # | ||
| CREATE TABLE t2 AS VALUES (1, 10, 100) AS new; | ||
| ERROR 42000: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use | ||
| # | ||
| # Cleanup | ||
| # | ||
| DROP TABLE t1; | ||
| DROP TABLE IF EXISTS t2; | ||
| # | ||
| # End of tests | ||
| # |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| --echo # | ||
| --echo # MDEV-29919: Support INSERT ... VALUES AS alias ON DUPLICATE KEY UPDATE | ||
| --echo # | ||
|
|
||
| # | ||
| # This test validates the row alias syntax for INSERT ON DUPLICATE KEY UPDATE | ||
| # which allows referencing inserted values using alias.column instead of VALUES(column) | ||
| # | ||
|
|
||
| --echo # | ||
| --echo # Test setup | ||
| --echo # | ||
| CREATE TABLE t1 ( | ||
| a INT PRIMARY KEY, | ||
| b INT, | ||
| c INT | ||
| ); | ||
|
|
||
| --echo # | ||
| --echo # Basic INSERT AS alias ON DUPLICATE KEY UPDATE | ||
| --echo # | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b, c = new.c; | ||
| SELECT * FROM t1; | ||
|
|
||
| --echo # | ||
| --echo # Multiple rows with AS alias | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200), (2, 30, 300) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b; | ||
| SELECT * FROM t1 ORDER BY a; | ||
|
|
||
| --echo # | ||
| --echo # Expression using alias columns | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 5, 50) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b + new.c, c = new.a * 10; | ||
| SELECT * FROM t1; | ||
|
|
||
| --echo # | ||
| --echo # Mix of alias and table column references | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 20, 200) AS new | ||
| ON DUPLICATE KEY UPDATE b = new.b, c = t1.c + new.c; | ||
| SELECT * FROM t1; | ||
|
|
||
| --echo # | ||
| --echo # INSERT without ON DUPLICATE KEY (alias should be ignored) | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100) AS new; | ||
| SELECT * FROM t1; | ||
|
|
||
| --echo # | ||
| --echo # Different alias names | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| INSERT INTO t1 VALUES (1, 99, 999) AS inserted_row | ||
| ON DUPLICATE KEY UPDATE b = inserted_row.b, c = inserted_row.c; | ||
| SELECT * FROM t1; | ||
|
|
||
| --echo # | ||
| --echo # Alias cannot be the same as the target table name | ||
| --echo # | ||
| TRUNCATE TABLE t1; | ||
| INSERT INTO t1 VALUES (1, 10, 100); | ||
| --error ER_NONUNIQ_TABLE | ||
| INSERT INTO t1 VALUES (1, 50, 500) AS t1 | ||
| ON DUPLICATE KEY UPDATE b = t1.b; | ||
|
|
||
| --echo # | ||
| --echo # Verify that AS alias is NOT allowed in REPLACE | ||
| --echo # | ||
| --error ER_SYNTAX_ERROR | ||
| REPLACE INTO t1 VALUES (1, 50, 500) AS new; | ||
|
|
||
| --echo # | ||
| --echo # Verify that AS alias is NOT allowed in CREATE ... VALUES | ||
| --echo # | ||
| --error ER_SYNTAX_ERROR | ||
| CREATE TABLE t2 AS VALUES (1, 10, 100) AS new; | ||
|
|
||
| --echo # | ||
| --echo # Cleanup | ||
| --echo # | ||
| DROP TABLE t1; | ||
| --disable_warnings | ||
| DROP TABLE IF EXISTS t2; | ||
| --enable_warnings | ||
|
|
||
| --echo # | ||
| --echo # End of tests | ||
| --echo # | ||
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
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
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
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
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
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.
Uh oh!
There was an error while loading. Please reload this page.