Skip to content

Commit 07e867c

Browse files
lovasoaalamb
authored andcommitted
Support for single-quoted identifiers (apache#1021)
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
1 parent bb53ee7 commit 07e867c

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
@@ -624,18 +624,29 @@ impl<'a> Parser<'a> {
624624

625625
let next_token = self.next_token();
626626
match next_token.token {
627-
Token::Word(w) if self.peek_token().token == Token::Period => {
628-
let mut id_parts: Vec<Ident> = vec![w.to_ident()];
629-
630-
while self.consume_token(&Token::Period) {
631-
let next_token = self.next_token();
632-
match next_token.token {
633-
Token::Word(w) => id_parts.push(w.to_ident()),
634-
Token::Mul => {
635-
return Ok(WildcardExpr::QualifiedWildcard(ObjectName(id_parts)));
636-
}
637-
_ => {
638-
return self.expected("an identifier or a '*' after '.'", next_token);
627+
t @ (Token::Word(_) | Token::SingleQuotedString(_)) => {
628+
if self.peek_token().token == Token::Period {
629+
let mut id_parts: Vec<Ident> = vec![match t {
630+
Token::Word(w) => w.to_ident(),
631+
Token::SingleQuotedString(s) => Ident::with_quote('\'', s),
632+
_ => unreachable!(), // We matched above
633+
}];
634+
635+
while self.consume_token(&Token::Period) {
636+
let next_token = self.next_token();
637+
match next_token.token {
638+
Token::Word(w) => id_parts.push(w.to_ident()),
639+
Token::SingleQuotedString(s) => {
640+
// SQLite has single-quoted identifiers
641+
id_parts.push(Ident::with_quote('\'', s))
642+
}
643+
Token::Mul => {
644+
return Ok(WildcardExpr::QualifiedWildcard(ObjectName(id_parts)));
645+
}
646+
_ => {
647+
return self
648+
.expected("an identifier or a '*' after '.'", next_token);
649+
}
639650
}
640651
}
641652
}
@@ -834,6 +845,9 @@ impl<'a> Parser<'a> {
834845
let next_token = self.next_token();
835846
match next_token.token {
836847
Token::Word(w) => id_parts.push(w.to_ident()),
848+
Token::SingleQuotedString(s) => {
849+
id_parts.push(Ident::with_quote('\'', s))
850+
}
837851
_ => {
838852
return self
839853
.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)