2 # Bug#40277 SHOW CREATE VIEW returns invalid SQL
3 # Bug#41999 SHOW CREATE VIEW returns invalid SQL if subquery is used in SELECT list
5 # 65 characters exceed the maximum length of a column identifier. The system cannot derive the name from statement.
6 # Constant with length = 65 . Expect to get the identifier 'Name_exp_1'.
7 CREATE VIEW v1 AS SELECT '<--- 65 char including the arrows --->';
8 SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'v1';
12 CREATE VIEW v1 AS select '<--- 65 char including the arrows --->' AS `Name_exp_1`;
14 CREATE VIEW v1 AS select '<--- 65 char including the arrows --->' AS `Name_exp_1`;
16 # Subquery with length = 65 . Expect to get the identifier 'Name_exp_1'.
17 # Attention: Identifier for the column within the subquery will be not generated.
18 CREATE VIEW v1 AS SELECT (SELECT '<--- 54 char including the arrows (+ 11 outside) -->');
19 SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'v1';
23 CREATE VIEW v1 AS select (select '<--- 54 char including the arrows (+ 11 outside) -->') AS `Name_exp_1`;
25 CREATE VIEW v1 AS select (select '<--- 54 char including the arrows (+ 11 outside) -->') AS `Name_exp_1`;
27 # -----------------------------------------------------------------------------------------------------------------
28 # 64 characters are the maximum length of a column identifier. The system can derive the name from the statement.
29 CREATE VIEW v1 AS SELECT '<--- 64 char including the arrows --->';
30 SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'v1';
32 <--- 64 char including the arrows --->
34 CREATE VIEW v1 AS select '<--- 64 char including the arrows --->' AS `<--- 64 char including the arrows --->`;
36 CREATE VIEW v1 AS select '<--- 64 char including the arrows --->' AS `<--- 64 char including the arrows --->`;
38 CREATE VIEW v1 AS SELECT (SELECT '<--- 53 char including the arrows (+ 11 outside) --->');
39 SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'v1';
41 (SELECT '<--- 53 char including the arrows (+ 11 outside) --->')
43 CREATE VIEW v1 AS select (select '<--- 53 char including the arrows (+ 11 outside) --->') AS `(SELECT '<--- 53 char including the arrows (+ 11 outside) --->')`;
45 CREATE VIEW v1 AS select (select '<--- 53 char including the arrows (+ 11 outside) --->') AS `(SELECT '<--- 53 char including the arrows (+ 11 outside) --->')`;
47 # -----------------------------------------------------------------------------------------------------------------
48 # Identifiers must not have trailing spaces. The system cannot derive the name from a constant with trailing space.
49 # Generated identifiers have at their end the position within the select column list.
50 # 'c2 ' -> 'Name_exp_1' , ' c4 ' -> 'Name_exp_2'
51 CREATE VIEW v1 AS SELECT 'c1', 'c2 ', ' c3', ' c4 ';
52 SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = 'test' AND TABLE_NAME = 'v1';
59 CREATE VIEW v1 AS select 'c1' AS `c1`,'c2 ' AS `Name_exp_2`,' c3' AS `c3`,' c4 ' AS `Name_exp_4`;
61 CREATE VIEW v1 AS select 'c1' AS `c1`,'c2 ' AS `Name_exp_2`,' c3' AS `c3`,' c4 ' AS `Name_exp_4`;
64 # Bug#40277 SHOW CREATE VIEW returns invalid SQL
66 DROP VIEW IF EXISTS v1;
67 DROP TABLE IF EXISTS t1,t2;
68 # Column name exceeds the maximum length.
69 CREATE VIEW v1 AS SELECT '0000000000 1111111111 2222222222 3333333333 4444444444 5555555555';
71 CREATE VIEW v1 AS select '0000000000 1111111111 2222222222 3333333333 4444444444 5555555555' AS `Name_exp_1`;
73 # Column names with leading trailing spaces.
74 CREATE VIEW v1 AS SELECT 'c1', 'c2 ', ' c3', ' c4 ';
76 CREATE VIEW v1 AS select 'c1' AS `c1`,'c2 ' AS `Name_exp_2`,' c3' AS `c3`,' c4 ' AS `Name_exp_4`;
78 # Column name conflicts with a auto-generated one.
79 CREATE VIEW v1 AS SELECT 'c1', 'c2 ', ' c3', ' c4 ', 'Name_exp_2';
81 CREATE VIEW v1 AS select 'c1' AS `c1`,'c2 ' AS `Name_exp_2`,' c3' AS `c3`,' c4 ' AS `Name_exp_4`,'Name_exp_2' AS `My_exp_Name_exp_2`;
83 # Invalid conlumn name in subquery.
84 CREATE VIEW v1 AS SELECT (SELECT ' c1 ');
86 CREATE VIEW v1 AS select (select ' c1 ') AS `(SELECT ' c1 ')`;
88 CREATE TABLE t1(a INT);
89 CREATE TABLE t2 LIKE t1;
90 # Test alias in subquery
91 CREATE VIEW v1 AS SELECT a FROM t1 WHERE EXISTS (SELECT 1 FROM t2 AS b WHERE b.a = 0);
93 CREATE VIEW v1 AS select `test`.`t1`.`a` AS `a` from `test`.`t1` where exists(select 1 from `test`.`t2` `b` where (`b`.`a` = 0));
95 # Test column alias in subquery
96 CREATE VIEW v1 AS SELECT a FROM t1 WHERE EXISTS (SELECT a AS alias FROM t1 GROUP BY alias);
98 View Create View character_set_client collation_connection
99 v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` where exists(select `t1`.`a` AS `alias` from `t1` group by `t1`.`a`) latin1 latin1_swedish_ci
101 CREATE VIEW v1 AS select `test`.`t1`.`a` AS `a` from `test`.`t1` where exists(select `test`.`t1`.`a` AS `alias` from `test`.`t1` group by `test`.`t1`.`a`);
103 # Alias as the expression column name.
104 CREATE VIEW v1 AS SELECT a FROM t1 WHERE EXISTS (SELECT ' a ' AS alias FROM t1 GROUP BY alias);
106 View Create View character_set_client collation_connection
107 v1 CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `v1` AS select `t1`.`a` AS `a` from `t1` where exists(select ' a ' AS `alias` from `t1` group by ' a ') latin1 latin1_swedish_ci
109 CREATE VIEW v1 AS select `test`.`t1`.`a` AS `a` from `test`.`t1` where exists(select ' a ' AS `alias` from `test`.`t1` group by ' a ');