diff --git a/pegjs/mariadb.pegjs b/pegjs/mariadb.pegjs index 34a55f4f..af942c4b 100644 --- a/pegjs/mariadb.pegjs +++ b/pegjs/mariadb.pegjs @@ -2809,8 +2809,9 @@ primary / cast_expr / case_expr / interval_expr - / literal + / literal_basic / column_ref + / literal_numeric / param / LPAREN __ list:or_and_where_expr __ RPAREN { list.parentheses = true; @@ -2936,6 +2937,7 @@ column column_name = start:ident_start parts:column_part* { return start + parts.join(''); } + / start:digits parts:column_part+ { return start + parts.join(''); } ident_name = start:ident_start parts:ident_part* { return start + parts.join(''); } @@ -3338,16 +3340,18 @@ signedness = KW_SIGNED / KW_UNSIGNED -literal +literal_basic = b:('binary'i / '_binary'i)? __ s:literal_string ca:(__ collate_expr)? { if (b) s.prefix = b.toLowerCase() if (ca) s.suffix = { collate: ca[1] } return s } - / literal_numeric / literal_bool / literal_null / literal_datetime + +literal + = literal_basic / literal_numeric literal_list = head:literal tail:(__ COMMA __ literal)* { diff --git a/pegjs/mysql.pegjs b/pegjs/mysql.pegjs index 8d623afa..ff476de2 100644 --- a/pegjs/mysql.pegjs +++ b/pegjs/mysql.pegjs @@ -3086,8 +3086,9 @@ primary / cast_expr / case_expr / interval_expr - / literal + / literal_basic / column_ref + / literal_numeric / param / LPAREN __ list:or_and_where_expr __ RPAREN { list.parentheses = true @@ -3228,6 +3229,7 @@ column column_name = start:ident_start parts:column_part* { return start + parts.join(''); } + / start:digits parts:column_part+ { return start + parts.join(''); } ident_name = start:ident_start parts:ident_part* { return start + parts.join(''); } @@ -3629,16 +3631,19 @@ signedness = KW_SIGNED / KW_UNSIGNED -literal +literal_basic = b:('binary'i / '_binary'i)? __ s:literal_string ca:(__ collate_expr)? { if (b) s.prefix = b.toLowerCase() if (ca) s.suffix = { collate: ca[1] } return s } - / literal_numeric / literal_bool / literal_null / literal_datetime + +literal + = literal_basic / literal_numeric + literal_list = head:literal tail:(__ COMMA __ literal)* { diff --git a/test/mysql-mariadb.spec.js b/test/mysql-mariadb.spec.js index 62c3a4f8..bf319660 100644 --- a/test/mysql-mariadb.spec.js +++ b/test/mysql-mariadb.spec.js @@ -1130,6 +1130,13 @@ describe('mysql', () => { 'CREATE TABLE `visits` (`done` BIT)' ] }, + { + title: 'column name start with digit', + sql: [ + 'select 4k_pic from table1', + 'SELECT `4k_pic` FROM `table1`' + ] + }, ] SQL_LIST.forEach(sqlInfo => { const { title, sql } = sqlInfo