Skip to content

Commit b8ed048

Browse files
yoavcloudayman-sigma
authored andcommitted
Redshift utf8 idents (apache#1915)
1 parent 9240c0b commit b8ed048

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
@@ -11071,10 +11071,17 @@ fn parse_non_latin_identifiers() {
1107111071
Box::new(RedshiftSqlDialect {}),
1107211072
Box::new(MySqlDialect {}),
1107311073
]);
11074-
1107511074
supported_dialects.verified_stmt("SELECT a.説明 FROM test.public.inter01 AS a");
1107611075
supported_dialects.verified_stmt("SELECT a.説明 FROM inter01 AS a, inter01_transactions AS b WHERE a.説明 = b.取引 GROUP BY a.説明");
1107711076
supported_dialects.verified_stmt("SELECT 説明, hühnervögel, garçon, Москва, 東京 FROM inter01");
11077+
11078+
let supported_dialects = TestedDialects::new(vec![
11079+
Box::new(GenericDialect {}),
11080+
Box::new(DuckDbDialect {}),
11081+
Box::new(PostgreSqlDialect {}),
11082+
Box::new(MsSqlDialect {}),
11083+
Box::new(MySqlDialect {}),
11084+
]);
1107811085
assert!(supported_dialects
1107911086
.parse_sql_statements("SELECT 💝 FROM table1")
1108011087
.is_err());

tests/sqlparser_redshift.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,3 +408,8 @@ fn parse_extract_single_quotes() {
408408
fn parse_string_literal_backslash_escape() {
409409
redshift().one_statement_parses_to(r#"SELECT 'l\'auto'"#, "SELECT 'l''auto'");
410410
}
411+
412+
#[test]
413+
fn parse_utf8_multibyte_idents() {
414+
redshift().verified_stmt("SELECT 🚀.city AS 🎸 FROM customers AS 🚀");
415+
}

0 commit comments

Comments
 (0)