Skip to content

Add identifier unicode support in Mysql, Postgres and Redshift #1933

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Jul 14, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/dialect/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ impl Dialect for MySqlDialect {
}

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

fn is_delimited_identifier_start(&self, ch: char) -> bool {
Expand Down
4 changes: 3 additions & 1 deletion src/dialect/postgresql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ impl Dialect for PostgreSqlDialect {
}

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

fn supports_unicode_string_literal(&self) -> bool {
Expand Down
4 changes: 2 additions & 2 deletions src/dialect/redshift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ impl Dialect for RedshiftSqlDialect {
}

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

/// redshift has `CONVERT(type, value)` instead of `CONVERT(value, type)`
Expand Down
11 changes: 11 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16133,3 +16133,14 @@ SELECT * FROM tbl2
assert_eq!(stmts.len(), 2);
assert!(stmts.iter().all(|s| matches!(s, Statement::Query { .. })));
}

#[test]
fn test_identifier_unicode_support() {
let sql = r#"SELECT phoneǤЖשचᎯ⻩☯♜🦄⚛🀄ᚠ⌛🌀 AS tbl FROM customers"#;
let dialects = TestedDialects::new(vec![
Box::new(MySqlDialect {}),
Box::new(RedshiftSqlDialect {}),
Box::new(PostgreSqlDialect {}),
]);
let _ = dialects.verified_stmt(sql);
}
Loading