Skip to content

Commit 1cd3035

Browse files
committed
add support for single-quoted identifiers
This does not support single-quoted table names, but supports the most common case of select tablename.'column' from tablename
1 parent 83cb734 commit 1cd3035

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/parser/mod.rs

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -618,18 +618,30 @@ impl<'a> Parser<'a> {
618618

619619
let next_token = self.next_token();
620620
match next_token.token {
621-
Token::Word(w) if self.peek_token().token == Token::Period => {
622-
let mut id_parts: Vec<Ident> = vec![w.to_ident()];
623-
624-
while self.consume_token(&Token::Period) {
625-
let next_token = self.next_token();
626-
match next_token.token {
627-
Token::Word(w) => id_parts.push(w.to_ident()),
628-
Token::Mul => {
629-
return Ok(WildcardExpr::QualifiedWildcard(ObjectName(id_parts)));
630-
}
631-
_ => {
632-
return self.expected("an identifier or a '*' after '.'", next_token);
621+
t @ (Token::Word(_) | Token::SingleQuotedString(_)) => {
622+
if self.peek_token().token == Token::Period {
623+
let mut id_parts: Vec<Ident> = vec![match t {
624+
Token::Word(w) => w.to_ident(),
625+
Token::SingleQuotedString(s) => Ident::with_quote('\'', s),
626+
Token::DoubleQuotedString(s) => Ident::with_quote('"', s),
627+
_ => unreachable!(), // We matched above
628+
}];
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::SingleQuotedString(s) => {
635+
// SQLite has single-quoted identifiers
636+
id_parts.push(Ident::with_quote('\'', s))
637+
}
638+
Token::Mul => {
639+
return Ok(WildcardExpr::QualifiedWildcard(ObjectName(id_parts)));
640+
}
641+
_ => {
642+
return self
643+
.expected("an identifier or a '*' after '.'", next_token);
644+
}
633645
}
634646
}
635647
}
@@ -825,6 +837,9 @@ impl<'a> Parser<'a> {
825837
let next_token = self.next_token();
826838
match next_token.token {
827839
Token::Word(w) => id_parts.push(w.to_ident()),
840+
Token::SingleQuotedString(s) => {
841+
id_parts.push(Ident::with_quote('\'', s))
842+
}
828843
_ => {
829844
return self
830845
.expected("an identifier or a '*' after '.'", next_token);

tests/sqlparser_sqlite.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,12 @@ fn parse_create_table_with_strict() {
290290
}
291291
}
292292

293+
#[test]
294+
fn parse_single_quoted_identified() {
295+
sqlite().verified_only_select("SELECT 't'.*, t.'x' FROM 't'");
296+
// TODO: add support for select 't'.x
297+
}
298+
293299
#[test]
294300
fn parse_attach_database() {
295301
let sql = "ATTACH DATABASE 'test.db' AS test";

0 commit comments

Comments
 (0)