Details
Description
I never noticed this or never thought it is a problem, but please look at this post:
http://blog.mclaughlinsoftware.com/2014/06/15/mysql-insert-from-query/
The "problem" is that parenthesis are allowed for INSERT (SELECT), but not for INSERT (SELECT UNION), and someone can conclude that INSERT SELECT UNION is not supported:
MariaDB [test]> INSERT INTO t3 (SELECT a, NULL AS b FROM t2); Query OK, 3 rows affected (0.08 sec) Records: 3 Duplicates: 0 Warnings: 0 MariaDB [test]> INSERT INTO t3 (SELECT a, NULL AS b FROM t1 UNION SELECT * FROM t2); ERROR 1064 (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 near 'UNION SELECT * FROM t2)' at line 1 MariaDB [test]> INSERT INTO t3 SELECT a, NULL AS b FROM t1 UNION SELECT * FROM t2; Query OK, 6 rows affected (0.08 sec) Records: 6 Duplicates: 0 Warnings: 0
Gliffy Diagrams
Attachments
Activity
- All
- Comments
- Work Log
- History
- Activity
- Transitions
considering: https://mariadb.com/kb/en/insert-select/
MariaDB [test]> INSERT INTO t3 (SELECT a, NULL AS b FROM t2);
this should not work
MariaDB [test]> INSERT INTO t3 (SELECT a, NULL AS b FROM t1 UNION SELECT * FROM t2);
this should not work
MariaDB [test]> INSERT INTO t3 SELECT a, NULL AS b FROM t1 UNION SELECT * FROM t2;
this should work