diff --git a/mysql-test/r/win.result b/mysql-test/r/win.result index bac00adfe54..cfe3ebe6a3c 100644 --- a/mysql-test/r/win.result +++ b/mysql-test/r/win.result @@ -3273,3 +3273,19 @@ row_number() over (partition by i order by i) i 1 1 1 2 DROP TABLE t1; +# +# MDEV-13384: "window" seems like a reserved column name but it's not listed as one +# +# Currently we allow window as an identifier, except for table aliases. +# +CREATE TABLE door (id INT, window VARCHAR(10)); +SELECT id +FROM door as window; +ERROR 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 'window' at line 2 +SELECT id, window +FROM door; +id window +SELECT id, window +FROM door as window; +ERROR 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 'window' at line 2 +DROP TABLE door; diff --git a/mysql-test/t/win.test b/mysql-test/t/win.test index 52819061570..1e747e59a1a 100644 --- a/mysql-test/t/win.test +++ b/mysql-test/t/win.test @@ -2036,3 +2036,24 @@ PREPARE stmt FROM "SELECT row_number() over (partition by i order by i), i FROM EXECUTE stmt; DROP TABLE t1; + +--echo # +--echo # MDEV-13384: "window" seems like a reserved column name but it's not listed as one +--echo # +--echo # Currently we allow window as an identifier, except for table aliases. +--echo # + +CREATE TABLE door (id INT, window VARCHAR(10)); + +--error ER_PARSE_ERROR +SELECT id +FROM door as window; + +SELECT id, window +FROM door; + +--error ER_PARSE_ERROR +SELECT id, window +FROM door as window; + +DROP TABLE door; diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 997e4940a16..0232f4fc5be 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -1740,7 +1740,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); IDENT_sys TEXT_STRING_sys TEXT_STRING_literal NCHAR_STRING opt_component key_cache_name sp_opt_label BIN_NUM label_ident TEXT_STRING_filesystem ident_or_empty - opt_constraint constraint opt_ident + opt_constraint constraint opt_ident ident_table_alias %type opt_table_alias @@ -1893,7 +1893,7 @@ bool my_yyoverflow(short **a, YYSTYPE **b, ulong *yystacksize); %type precision opt_precision float_options -%type keyword keyword_sp +%type keyword keyword_sp keyword_alias %type user grant_user grant_role user_or_role current_role admin_option_for_role user_maybe_role @@ -11402,7 +11402,7 @@ table_alias: opt_table_alias: /* empty */ { $$=0; } - | table_alias ident + | table_alias ident_table_alias { $$= (LEX_STRING*) thd->memdup(&$2,sizeof(LEX_STRING)); if ($$ == NULL) @@ -14458,6 +14458,16 @@ TEXT_STRING_filesystem: MYSQL_YYABORT; } } + +ident_table_alias: + IDENT_sys { $$= $1; } + | keyword_alias + { + $$.str= thd->strmake($1.str, $1.length); + if ($$.str == NULL) + MYSQL_YYABORT; + $$.length= $1.length; + } ; ident: @@ -14552,8 +14562,8 @@ user: user_maybe_role } ; -/* Keyword that we allow for identifiers (except SP labels) */ -keyword: +/* Keywords which we allow as table aliases. */ +keyword_alias: keyword_sp {} | ASCII_SYM {} | BACKUP_SYM {} @@ -14627,6 +14637,10 @@ keyword: | UPGRADE_SYM {} ; + +/* Keyword that we allow for identifiers (except SP labels) */ +keyword: keyword_alias | WINDOW_SYM ; + /* * Keywords that we allow for labels in SPs. * Anything that's the beginning of a statement or characteristics