Skip to content

Commit c5e6ba5

Browse files
authored
Add identifier unicode support in Mysql, Postgres and Redshift (#1933)
1 parent 9b9ffe4 commit c5e6ba5

File tree

4 files changed

+19
-4
lines changed

4 files changed

+19
-4
lines changed

src/dialect/mysql.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@ impl Dialect for MySqlDialect {
5151
}
5252

5353
fn is_identifier_part(&self, ch: char) -> bool {
54-
self.is_identifier_start(ch) || ch.is_ascii_digit()
54+
self.is_identifier_start(ch) || ch.is_ascii_digit() ||
55+
// MySQL implements Unicode characters in identifiers.
56+
!ch.is_ascii()
5557
}
5658

5759
fn is_delimited_identifier_start(&self, ch: char) -> bool {

src/dialect/postgresql.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,9 @@ impl Dialect for PostgreSqlDialect {
7272
}
7373

7474
fn is_identifier_part(&self, ch: char) -> bool {
75-
ch.is_alphabetic() || ch.is_ascii_digit() || ch == '$' || ch == '_'
75+
ch.is_alphabetic() || ch.is_ascii_digit() || ch == '$' || ch == '_' ||
76+
// PostgreSQL implements Unicode characters in identifiers.
77+
!ch.is_ascii()
7678
}
7779

7880
fn supports_unicode_string_literal(&self) -> bool {

src/dialect/redshift.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,9 @@ impl Dialect for RedshiftSqlDialect {
8686
}
8787

8888
fn is_identifier_part(&self, ch: char) -> bool {
89-
// Extends Postgres dialect with sharp and UTF-8 multibyte chars
89+
// UTF-8 multibyte characters are supported in identifiers via the PostgreSqlDialect.
9090
// https://docs.aws.amazon.com/redshift/latest/dg/r_names.html
91-
PostgreSqlDialect {}.is_identifier_part(ch) || ch == '#' || !ch.is_ascii()
91+
PostgreSqlDialect {}.is_identifier_part(ch) || ch == '#'
9292
}
9393

9494
/// redshift has `CONVERT(type, value)` instead of `CONVERT(value, type)`

tests/sqlparser_common.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16136,3 +16136,14 @@ SELECT * FROM tbl2
1613616136
assert_eq!(stmts.len(), 2);
1613716137
assert!(stmts.iter().all(|s| matches!(s, Statement::Query { .. })));
1613816138
}
16139+
16140+
#[test]
16141+
fn test_identifier_unicode_support() {
16142+
let sql = r#"SELECT phoneǤЖשचᎯ⻩☯♜🦄⚛🀄ᚠ⌛🌀 AS tbl FROM customers"#;
16143+
let dialects = TestedDialects::new(vec![
16144+
Box::new(MySqlDialect {}),
16145+
Box::new(RedshiftSqlDialect {}),
16146+
Box::new(PostgreSqlDialect {}),
16147+
]);
16148+
let _ = dialects.verified_stmt(sql);
16149+
}

0 commit comments

Comments
 (0)