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

Syntax error on ((SELECT ...) UNION (SELECT ...))

    XMLWordPrintable

Details

    • Bug
    • Status: Closed (View Workflow)
    • Major
    • Resolution: Duplicate
    • 5.5, 10.0, 10.1, 10.2
    • 10.4.0
    • Parser

    Description

      I create and populate a table:

      DROP TABLE t1;
      CREATE TABLE t1 (a INT);
      INSERT INTO t1 VALUES (10);
      INSERT INTO t1 VALUES (20);
      INSERT INTO t1 VALUES (30);
      

      Now I run this SQL Standard compliant query:

      ((SELECT a FROM t1) UNION (SELECT a FROM t1));
      

      it returns a syntax error:

      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 a FROM t1))' at line 1
      

      PostgreSQL and Oracle work fine on the same query.

      This Standard-compliant query also returns a syntax_error:

      (SELECT * FROM t1 UNION SELECT * FROM t1);
      

      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 t1)' at line 1
      

      PostgreSQL and Oracle work fine on this query.

      This query returns a syntax error:

      ((SELECT a FROM t1) LIMIT 1);
      

      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 'LIMIT 1)' at line 1
      

      It should return a result. It works fine in PostreSQL. Also, it is a direct equivalent query to this Standard-compliant version:

      ((SELECT a FROM t1) FETCH FIRST 1 ROWS ONLY);
      

      Another example:

      SELECT * FROM (SELECT 1 UNION (SELECT 2 UNION SELECT 3)) t1;
      

      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 3) t1' at line 1
      

      The same query works in PostgreSQL.
      A similar query works in Oracle (with FROM DUAL added, and with no derived table alias)

      SELECT * FROM (SELECT 1 FROM DUAL UNION (SELECT 2 FROM DUAL UNION SELECT 3 FROM DUAL))
      

      Attachments

        Issue Links

          Activity

            People

              sanja Oleksandr Byelkin
              bar Alexander Barkov
              Votes:
              0 Vote for this issue
              Watchers:
              4 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Git Integration

                  Error rendering 'com.xiplink.jira.git.jira_git_plugin:git-issue-webpanel'. Please contact your Jira administrators.