diff --git a/pegjs/db2.pegjs b/pegjs/db2.pegjs index f3fac5b7..0cd7095b 100644 --- a/pegjs/db2.pegjs +++ b/pegjs/db2.pegjs @@ -1936,9 +1936,9 @@ column_name ident_name = start:ident_start parts:ident_part* { return start + parts.join(''); } -ident_start = [A-Za-z_] +ident_start = [A-Za-z_\u4e00-\u9fa5] -ident_part = [A-Za-z0-9_] +ident_part = [A-Za-z0-9_$\u4e00-\u9fa5\u00C0-\u017F] // to support column name like `cf1:name` in hbase column_part = [A-Za-z0-9_:] diff --git a/pegjs/flinksql.pegjs b/pegjs/flinksql.pegjs index ae5f8a6e..098511f6 100644 --- a/pegjs/flinksql.pegjs +++ b/pegjs/flinksql.pegjs @@ -2796,9 +2796,9 @@ ident_name return start + parts.join(''); } -ident_start = [A-Za-z_] +ident_start = [A-Za-z_\u4e00-\u9fa5] -ident_part = [A-Za-z0-9_\-] +ident_part = [A-Za-z0-9_\-$\u4e00-\u9fa5\u00C0-\u017F] // to support column name like `cf1:name` in hbase column_part = [A-Za-z0-9_] diff --git a/pegjs/hive.pegjs b/pegjs/hive.pegjs index 723cf352..b94066e9 100644 --- a/pegjs/hive.pegjs +++ b/pegjs/hive.pegjs @@ -1921,9 +1921,9 @@ column_name ident_name = start:ident_start parts:ident_part* { return start + parts.join(''); } -ident_start = [A-Za-z_] +ident_start = [A-Za-z_\u4e00-\u9fa5] -ident_part = [A-Za-z0-9_] +ident_part = [A-Za-z0-9_$\u4e00-\u9fa5\u00C0-\u017F] // to support column name like `cf1:name` in hbase column_part = [A-Za-z0-9_:] diff --git a/pegjs/mariadb.pegjs b/pegjs/mariadb.pegjs index 5b0a463c..f1daf2f3 100644 --- a/pegjs/mariadb.pegjs +++ b/pegjs/mariadb.pegjs @@ -2940,9 +2940,9 @@ column_name ident_name = start:ident_start parts:ident_part* { return start + parts.join(''); } -ident_start = [A-Za-z_] +ident_start = [A-Za-z_\u4e00-\u9fa5] -ident_part = [A-Za-z0-9_$] +ident_part = [A-Za-z0-9_$$\u4e00-\u9fa5\u00C0-\u017F] // to support column name like `cf1:name` in hbase column_part = [A-Za-z0-9_:] diff --git a/pegjs/mysql.pegjs b/pegjs/mysql.pegjs index 80e6b62d..c25a275a 100644 --- a/pegjs/mysql.pegjs +++ b/pegjs/mysql.pegjs @@ -3231,7 +3231,7 @@ column_name ident_name = start:ident_start parts:ident_part* { return start + parts.join(''); } -ident_start = [A-Za-z_] +ident_start = [A-Za-z_\u4e00-\u9fa5] ident_part = [A-Za-z0-9_$\u0080-\uffff] diff --git a/pegjs/transactsql.pegjs b/pegjs/transactsql.pegjs index 5100539b..765c02e0 100644 --- a/pegjs/transactsql.pegjs +++ b/pegjs/transactsql.pegjs @@ -2421,7 +2421,8 @@ column_ref obj.db = db[0] obj.schema = schema[0] } - columnList.add(`select::${[obj.db, obj.schema, obj.table].join('.')}::${col}`); + const fullTableName = [obj.db, obj.schema, obj.table].filter(Boolean).join('.') || 'null' + columnList.add(`select::${fullTableName}::${col}`); return { type: 'column_ref', ...obj, @@ -2524,9 +2525,9 @@ ident_name_list return createList(head, tail) } -ident_start = [A-Za-z_@#] +ident_start = [A-Za-z_@#\u4e00-\u9fa5] -ident_part = [A-Za-z0-9_\-@$] +ident_part = [A-Za-z0-9_\-@$$\u4e00-\u9fa5\u00C0-\u017F] // to support column name like `cf1:name` in hbase column_part = [A-Za-z0-9_:] diff --git a/pegjs/trino.pegjs b/pegjs/trino.pegjs index dc998e79..ea0019b9 100644 --- a/pegjs/trino.pegjs +++ b/pegjs/trino.pegjs @@ -3551,7 +3551,7 @@ ident_name return start + parts.join(''); } -ident_start = [A-Za-z_] +ident_start = [A-Za-z_\u4e00-\u9fa5] ident_part = [A-Za-z0-9_$\u0080-\uffff] diff --git a/test/transactsql.spec.js b/test/transactsql.spec.js index d400b7f1..0f57c279 100644 --- a/test/transactsql.spec.js +++ b/test/transactsql.spec.js @@ -374,7 +374,21 @@ describe('transactsql', () => { 'SELECT * INTO #temp_table FROM tableName', 'SELECT * INTO [#temp_table] FROM [tableName]' ] - } + }, + { + title: 'convert function', + sql: [ + 'SELECT a.username FROM users a WHERE a.end_time = CONVERT(VARCHAR,getdate(),23)', + 'SELECT [a].[username] FROM [users] AS [a] WHERE [a].[end_time] = CONVERT([VARCHAR], getdate(), 23)', + ] + }, + { + title: 'column as chinese name', + sql: [ + 'SELECT a.username 姓名 FROM users a', + 'SELECT [a].[username] AS [姓名] FROM [users] AS [a]' + ] + }, ] SQL_LIST.forEach(sqlInfo => { const { title, sql } = sqlInfo