Skip to content

Commit

Permalink
Redshift: Fix parsing for quoted numbered columns
Browse files Browse the repository at this point in the history
  • Loading branch information
7phs committed Dec 3, 2024
1 parent 4ab3ab9 commit 3f295b8
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/dialect/redshift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,18 @@ impl Dialect for RedshiftSqlDialect {
/// treating them as json path. If there is identifier then we assume
/// there is no json path.
fn is_proper_identifier_inside_quotes(&self, mut chars: Peekable<Chars<'_>>) -> bool {
// PartiQL uses square bracket as a start character and a quote is a beginning of quoted identifier
if let Some(quote_start) = chars.peek() {
if *quote_start == '"' {
return true;
}
};
chars.next();
let mut not_white_chars = chars.skip_while(|ch| ch.is_whitespace()).peekable();
if let Some(&ch) = not_white_chars.peek() {
return self.is_identifier_start(ch);
// PartiQL uses single quote as starting identification inside a quote
// It is a normal identifier if it has no single quote at the beginning
return ch != '\'' && self.is_identifier_start(ch);
}
false
}
Expand Down
12 changes: 12 additions & 0 deletions tests/sqlparser_redshift.rs
Original file line number Diff line number Diff line change
Expand Up @@ -353,3 +353,15 @@ fn test_parse_json_path_from() {
_ => panic!(),
}
}

#[test]
fn test_parse_select_numbered_columns() {
redshift_and_generic().verified_stmt(r#"SELECT 1 AS "1" FROM a"#);
}

#[test]
fn test_parse_create_numbered_columns() {
redshift_and_generic().verified_stmt(
r#"CREATE TABLE test_table_1 ("1" INT, "d" VARCHAR(155), "2" DOUBLE PRECISION)"#,
);
}

0 comments on commit 3f295b8

Please sign in to comment.