Skip to content

Commit

Permalink
Merge pull request #2175 from taozhi8833998/fix-column-name-digit-mysql
Browse files Browse the repository at this point in the history
fix: column name can start with digit in mysql
  • Loading branch information
taozhi8833998 authored Oct 16, 2024
2 parents 6175609 + 5d48745 commit 7af8a83
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 7af8a83

Please sign in to comment.