Uploaded image for project: 'MariaDB Server'
  1. MariaDB Server
  2. MDEV-6341

INSERT ... SELECT UNION with parenthesis

    Details

    • Type: Bug
    • Status: Open
    • Priority: Minor
    • Resolution: Unresolved
    • Affects Version/s: 5.5.38, 10.0.12
    • Fix Version/s: 10.0, 5.5
    • Component/s: None
    • Labels:
      None

      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

            Hide
            rspadim roberto spadim added a comment -

            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

            Show
            rspadim roberto spadim added a comment - 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

              People

              • Assignee:
                Unassigned
                Reporter:
                f_razzoli Federico Razzoli
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated: