diff options
author | Alexander Barkov <bar@mariadb.org> | 2016-06-15 18:24:05 +0400 |
---|---|---|
committer | Sergei Golubchik <serg@mariadb.org> | 2016-06-30 11:43:02 +0200 |
commit | b3e11d33db5ab866c710ff8dd8653c314578f545 (patch) | |
tree | 100918cd227039f03e7628903d434fe4bc4fccb9 /sql/sql_yacc.yy | |
parent | fb67cde2370f7427b3279309daac712c369f1cf8 (diff) | |
download | mariadb-git-b3e11d33db5ab866c710ff8dd8653c314578f545.tar.gz |
Adding a comment why we need column_default_non_parenthesized_expr
(a new rule in sql_yacc.yy)
Diffstat (limited to 'sql/sql_yacc.yy')
-rw-r--r-- | sql/sql_yacc.yy | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/sql/sql_yacc.yy b/sql/sql_yacc.yy index 3d0cbfb4c16..08e27a0c5bb 100644 --- a/sql/sql_yacc.yy +++ b/sql/sql_yacc.yy @@ -9512,6 +9512,34 @@ dyncall_create_list: } ; +/* + Expressions that the parser allows in a column DEFAULT clause + without parentheses. These expressions cannot end with a COLLATE clause. + + If we allowed any "expr" in DEFAULT clause, there would be a confusion + in queries like this: + CREATE TABLE t1 (a TEXT DEFAULT 'a' COLLATE latin1_bin); + It would be not clear what COLLATE stands for: + - the collation of the column `a`, or + - the collation of the string literal 'a' + + This restriction allows to parse the above query unambiguiusly: + COLLATE belongs to the column rather than the literal. + If one needs COLLATE to belong to the literal, parentheses must be used: + CREATE TABLE t1 (a TEXT DEFAULT ('a' COLLATE latin1_bin)); + Note: the COLLATE clause is rather meaningless here, but the query + is syntactically correct. + + Note, some of the expressions are not actually allowed in DEFAULT, + e.g. sum_expr, window_func_expr, ROW(...), VALUES(). + We could move them to simple_expr, but that would make + these two queries return a different error messages: + CREATE TABLE t1 (a INT DEFAULT AVG(1)); + CREATE TABLE t1 (a INT DEFAULT (AVG(1))); + The first query would return "syntax error". + Currenly both return: + Function or expression 'avg(' is not allowed for 'DEFAULT' ... +*/ column_default_non_parenthesized_expr: simple_ident | function_call_keyword |