[MDEV-12185] CTE alias does not work as part of view expression Created: 2017-03-06  Updated: 2020-08-25  Resolved: 2017-03-08

Status: Closed
Project: MariaDB Server
Component/s: Optimizer - CTE, Views
Affects Version/s: 10.2.4
Fix Version/s: 10.2.5

Type: Bug Priority: Major
Reporter: Alvin Richards (Inactive) Assignee: Igor Babaev
Resolution: Fixed Votes: 1
Labels: None


 Description   

Problem

CTE alias do not appear to work as part of a View definition. The view will be created without error, but selecting from the view results in

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 'alias2 as (select 2 AS `two`), select `alias1`.`one` AS `one`,`alias2`.`two` AS ' at line 1

Reproduce

Select works as expected with CTE

with alias1 as (select 1 as one), alias2 as (select 2 as two) select one, two from alias1, alias2;
+-----+-----+
| one | two |
+-----+-----+
|   1 |   2 |
+-----+-----+
1 row in set (0.00 sec)

View get created without error with the same CTE

create view vw as with alias1 as (select 1 as one), alias2 as (select 2 as two) select one, two from alias1, alias2;
Query OK, 0 rows affected (0.01 sec)

Query fails against the view

select * from vw; 
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 'alias2 as (select 2 AS `two`), select `alias1`.`one` AS `one`,`alias2`.`two` AS ' at line 1

Solution

If this is a valid construct, then the query should execute as expected (per the un-view version).

If this is an invalid construct, then the create view should fail.

Workaround

None at present



 Comments   
Comment by Igor Babaev [ 2017-03-08 ]

The fix for this bug was pushed into the 10.2 tree.

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