[MDEV-10028] Syntax error on ((SELECT ...) UNION (SELECT ...)) Created: 2016-05-05  Updated: 2018-07-09  Resolved: 2018-07-09

Status: Closed
Project: MariaDB Server
Component/s: Parser
Affects Version/s: 5.5, 10.0, 10.1, 10.2
Fix Version/s: 10.4.0

Type: Bug Priority: Major
Reporter: Alexander Barkov Assignee: Oleksandr Byelkin
Resolution: Duplicate Votes: 0
Labels: upstream

Issue Links:
Duplicate
duplicates MDEV-11953 support of brackets (parentheses) in ... Closed
Relates
relates to MDEV-6341 INSERT ... SELECT UNION with parenthesis Closed
relates to MDEV-8909 union parser cleanup Closed
relates to MDEV-10029 UNION + OUTFILE is confusing Open

 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))



 Comments   
Comment by Alexander Barkov [ 2016-05-05 ]

MySQL-5.7.12 is also affected.

Comment by Elena Stepanova [ 2016-05-05 ]

See also MDEV-6341

Comment by Oleksandr Byelkin [ 2018-04-11 ]

test put in https://jira.mariadb.org/browse/MDEV-11953

Comment by Oleksandr Byelkin [ 2018-07-09 ]

Fixed in MDEV-11953

Generated at Thu Feb 08 07:39:08 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.