mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-08-22 06:54:07 +00:00
Support for single-quoted identifiers (#1021)
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This commit is contained in:
parent
004a8dc5dd
commit
c5a7d6ccb9
2 changed files with 30 additions and 11 deletions
|
@ -620,18 +620,29 @@ impl<'a> Parser<'a> {
|
|||
|
||||
let next_token = self.next_token();
|
||||
match next_token.token {
|
||||
Token::Word(w) if self.peek_token().token == Token::Period => {
|
||||
let mut id_parts: Vec<Ident> = vec![w.to_ident()];
|
||||
t @ (Token::Word(_) | Token::SingleQuotedString(_)) => {
|
||||
if self.peek_token().token == Token::Period {
|
||||
let mut id_parts: Vec<Ident> = vec![match t {
|
||||
Token::Word(w) => w.to_ident(),
|
||||
Token::SingleQuotedString(s) => Ident::with_quote('\'', s),
|
||||
_ => unreachable!(), // We matched above
|
||||
}];
|
||||
|
||||
while self.consume_token(&Token::Period) {
|
||||
let next_token = self.next_token();
|
||||
match next_token.token {
|
||||
Token::Word(w) => id_parts.push(w.to_ident()),
|
||||
Token::Mul => {
|
||||
return Ok(WildcardExpr::QualifiedWildcard(ObjectName(id_parts)));
|
||||
}
|
||||
_ => {
|
||||
return self.expected("an identifier or a '*' after '.'", next_token);
|
||||
while self.consume_token(&Token::Period) {
|
||||
let next_token = self.next_token();
|
||||
match next_token.token {
|
||||
Token::Word(w) => id_parts.push(w.to_ident()),
|
||||
Token::SingleQuotedString(s) => {
|
||||
// SQLite has single-quoted identifiers
|
||||
id_parts.push(Ident::with_quote('\'', s))
|
||||
}
|
||||
Token::Mul => {
|
||||
return Ok(WildcardExpr::QualifiedWildcard(ObjectName(id_parts)));
|
||||
}
|
||||
_ => {
|
||||
return self
|
||||
.expected("an identifier or a '*' after '.'", next_token);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -830,6 +841,9 @@ impl<'a> Parser<'a> {
|
|||
let next_token = self.next_token();
|
||||
match next_token.token {
|
||||
Token::Word(w) => id_parts.push(w.to_ident()),
|
||||
Token::SingleQuotedString(s) => {
|
||||
id_parts.push(Ident::with_quote('\'', s))
|
||||
}
|
||||
_ => {
|
||||
return self
|
||||
.expected("an identifier or a '*' after '.'", next_token);
|
||||
|
|
|
@ -335,6 +335,11 @@ fn parse_create_table_with_strict() {
|
|||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_single_quoted_identified() {
|
||||
sqlite().verified_only_select("SELECT 't'.*, t.'x' FROM 't'");
|
||||
// TODO: add support for select 't'.x
|
||||
}
|
||||
#[test]
|
||||
fn parse_window_function_with_filter() {
|
||||
for func_name in [
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue