Skip to content

Commit

Permalink
fix: column name can start with digit in mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
taozhi8833998 committed Oct 15, 2024
1 parent ef66692 commit 5d48745
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
10 changes: 7 additions & 3 deletions pegjs/mariadb.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(''); }
Expand Down Expand Up @@ -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)* {
Expand Down
11 changes: 8 additions & 3 deletions pegjs/mysql.pegjs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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(''); }
Expand Down Expand Up @@ -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)* {
Expand Down
7 changes: 7 additions & 0 deletions test/mysql-mariadb.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5d48745

Please sign in to comment.