Skip to content

Commit 3f295b8

Browse files
author
aleksei.p
committed
Redshift: Fix parsing for quoted numbered columns
1 parent 4ab3ab9 commit 3f295b8

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

src/dialect/redshift.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,18 @@ impl Dialect for RedshiftSqlDialect {
4141
/// treating them as json path. If there is identifier then we assume
4242
/// there is no json path.
4343
fn is_proper_identifier_inside_quotes(&self, mut chars: Peekable<Chars<'_>>) -> bool {
44+
// PartiQL uses square bracket as a start character and a quote is a beginning of quoted identifier
45+
if let Some(quote_start) = chars.peek() {
46+
if *quote_start == '"' {
47+
return true;
48+
}
49+
};
4450
chars.next();
4551
let mut not_white_chars = chars.skip_while(|ch| ch.is_whitespace()).peekable();
4652
if let Some(&ch) = not_white_chars.peek() {
47-
return self.is_identifier_start(ch);
53+
// PartiQL uses single quote as starting identification inside a quote
54+
// It is a normal identifier if it has no single quote at the beginning
55+
return ch != '\'' && self.is_identifier_start(ch);
4856
}
4957
false
5058
}

tests/sqlparser_redshift.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -353,3 +353,15 @@ fn test_parse_json_path_from() {
353353
_ => panic!(),
354354
}
355355
}
356+
357+
#[test]
358+
fn test_parse_select_numbered_columns() {
359+
redshift_and_generic().verified_stmt(r#"SELECT 1 AS "1" FROM a"#);
360+
}
361+
362+
#[test]
363+
fn test_parse_create_numbered_columns() {
364+
redshift_and_generic().verified_stmt(
365+
r#"CREATE TABLE test_table_1 ("1" INT, "d" VARCHAR(155), "2" DOUBLE PRECISION)"#,
366+
);
367+
}

0 commit comments

Comments
 (0)