Skip to content

Commit f32a41a

Browse files
authored
Redshift utf8 idents (apache#1915)
1 parent 9ffc546 commit f32a41a

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

src/dialect/redshift.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,15 @@ impl Dialect for RedshiftSqlDialect {
8080
}
8181

8282
fn is_identifier_start(&self, ch: char) -> bool {
83-
// Extends Postgres dialect with sharp
84-
PostgreSqlDialect {}.is_identifier_start(ch) || ch == '#'
83+
// Extends Postgres dialect with sharp and UTF-8 multibyte chars
84+
// https://docs.aws.amazon.com/redshift/latest/dg/r_names.html
85+
PostgreSqlDialect {}.is_identifier_start(ch) || ch == '#' || !ch.is_ascii()
8586
}
8687

8788
fn is_identifier_part(&self, ch: char) -> bool {
88-
// Extends Postgres dialect with sharp
89-
PostgreSqlDialect {}.is_identifier_part(ch) || ch == '#'
89+
// Extends Postgres dialect with sharp and UTF-8 multibyte chars
90+
// https://docs.aws.amazon.com/redshift/latest/dg/r_names.html
91+
PostgreSqlDialect {}.is_identifier_part(ch) || ch == '#' || !ch.is_ascii()
9092
}
9193

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

tests/sqlparser_common.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11068,10 +11068,17 @@ fn parse_non_latin_identifiers() {
1106811068
Box::new(RedshiftSqlDialect {}),
1106911069
Box::new(MySqlDialect {}),
1107011070
]);
11071-
1107211071
supported_dialects.verified_stmt("SELECT a.説明 FROM test.public.inter01 AS a");
1107311072
supported_dialects.verified_stmt("SELECT a.説明 FROM inter01 AS a, inter01_transactions AS b WHERE a.説明 = b.取引 GROUP BY a.説明");
1107411073
supported_dialects.verified_stmt("SELECT 説明, hühnervögel, garçon, Москва, 東京 FROM inter01");
11074+
11075+
let supported_dialects = TestedDialects::new(vec![
11076+
Box::new(GenericDialect {}),
11077+
Box::new(DuckDbDialect {}),
11078+
Box::new(PostgreSqlDialect {}),
11079+
Box::new(MsSqlDialect {}),
11080+
Box::new(MySqlDialect {}),
11081+
]);
1107511082
assert!(supported_dialects
1107611083
.parse_sql_statements("SELECT 💝 FROM table1")
1107711084
.is_err());

tests/sqlparser_redshift.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -402,3 +402,8 @@ fn parse_extract_single_quotes() {
402402
fn parse_string_literal_backslash_escape() {
403403
redshift().one_statement_parses_to(r#"SELECT 'l\'auto'"#, "SELECT 'l''auto'");
404404
}
405+
406+
#[test]
407+
fn parse_utf8_multibyte_idents() {
408+
redshift().verified_stmt("SELECT 🚀.city AS 🎸 FROM customers AS 🚀");
409+
}

0 commit comments

Comments
 (0)