Skip to content

Commit c5a7d6c

Browse files
lovasoaalamb
andauthored
Support for single-quoted identifiers (#1021)
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent 004a8dc commit c5a7d6c

File tree

2 files changed

+31
-12
lines changed

2 files changed

+31
-12
lines changed

src/parser/mod.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -620,18 +620,29 @@ impl<'a> Parser<'a> {
620620

621621
let next_token = self.next_token();
622622
match next_token.token {
623-
Token::Word(w) if self.peek_token().token == Token::Period => {
624-
let mut id_parts: Vec<Ident> = vec![w.to_ident()];
625-
626-
while self.consume_token(&Token::Period) {
627-
let next_token = self.next_token();
628-
match next_token.token {
629-
Token::Word(w) => id_parts.push(w.to_ident()),
630-
Token::Mul => {
631-
return Ok(WildcardExpr::QualifiedWildcard(ObjectName(id_parts)));
632-
}
633-
_ => {
634-
return self.expected("an identifier or a '*' after '.'", next_token);
623+
t @ (Token::Word(_) | Token::SingleQuotedString(_)) => {
624+
if self.peek_token().token == Token::Period {
625+
let mut id_parts: Vec<Ident> = vec![match t {
626+
Token::Word(w) => w.to_ident(),
627+
Token::SingleQuotedString(s) => Ident::with_quote('\'', s),
628+
_ => unreachable!(), // We matched above
629+
}];
630+
631+
while self.consume_token(&Token::Period) {
632+
let next_token = self.next_token();
633+
match next_token.token {
634+
Token::Word(w) => id_parts.push(w.to_ident()),
635+
Token::SingleQuotedString(s) => {
636+
// SQLite has single-quoted identifiers
637+
id_parts.push(Ident::with_quote('\'', s))
638+
}
639+
Token::Mul => {
640+
return Ok(WildcardExpr::QualifiedWildcard(ObjectName(id_parts)));
641+
}
642+
_ => {
643+
return self
644+
.expected("an identifier or a '*' after '.'", next_token);
645+
}
635646
}
636647
}
637648
}
@@ -830,6 +841,9 @@ impl<'a> Parser<'a> {
830841
let next_token = self.next_token();
831842
match next_token.token {
832843
Token::Word(w) => id_parts.push(w.to_ident()),
844+
Token::SingleQuotedString(s) => {
845+
id_parts.push(Ident::with_quote('\'', s))
846+
}
833847
_ => {
834848
return self
835849
.expected("an identifier or a '*' after '.'", next_token);

tests/sqlparser_sqlite.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,11 @@ fn parse_create_table_with_strict() {
335335
}
336336
}
337337

338+
#[test]
339+
fn parse_single_quoted_identified() {
340+
sqlite().verified_only_select("SELECT 't'.*, t.'x' FROM 't'");
341+
// TODO: add support for select 't'.x
342+
}
338343
#[test]
339344
fn parse_window_function_with_filter() {
340345
for func_name in [

0 commit comments

Comments
 (0)