Skip to content
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

Support Snowflake - allow number as placeholder (e.g. :1) #1001

Merged
merged 4 commits into from
Oct 25, 2023
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
9 changes: 8 additions & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4759,7 +4759,14 @@ impl<'a> Parser<'a> {
Token::HexStringLiteral(ref s) => Ok(Value::HexStringLiteral(s.to_string())),
Token::Placeholder(ref s) => Ok(Value::Placeholder(s.to_string())),
tok @ Token::Colon | tok @ Token::AtSign => {
let ident = self.parse_identifier()?;
// Not calling self.parse_identifier()? because only in placeholder we want to check numbers as idfentifies
Copy link
Contributor

@alamb alamb Oct 25, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ makes sense to me

Suggested change
// Not calling self.parse_identifier()? because only in placeholder we want to check numbers as idfentifies
// Not calling self.parse_identifier()? because only in placeholder we want to check numbers as identifiers

// This because snowflake allows numbers as placeholders
let next_token = self.next_token();
let ident = match next_token.token {
Token::Word(w) => Ok(w.to_ident()),
Token::Number(w, false) => Ok(Ident::new(w)),
_ => self.expected("placeholder", next_token),
}?;
let placeholder = tok.to_string() + &ident.value;
Ok(Value::Placeholder(placeholder))
}
Expand Down
14 changes: 14 additions & 0 deletions tests/sqlparser_snowflake.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,20 @@ fn test_snowflake_trim() {
);
}

#[test]
fn test_number_placeholder() {
let sql_only_select = "SELECT :1";
let select = snowflake().verified_only_select(sql_only_select);
assert_eq!(
&Expr::Value(Value::Placeholder(":1".into())),
expr_from_projection(only(&select.projection))
);

snowflake()
.parse_sql_statements("alter role 1 with name = 'foo'")
.expect_err("should have failed");
}

#[test]
fn parse_position_not_function_columns() {
snowflake_and_generic()
Expand Down
Loading