Skip to content

Commit b36514d

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 b36514d

File tree

2 files changed

+33
-12
lines changed

2 files changed

+33
-12
lines changed

src/parser/mod.rs

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -618,18 +618,29 @@ 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) => { // SQLite has single-quoted identifiers
635+
id_parts.push(Ident::with_quote('\'', s))
636+
}
637+
Token::Mul => {
638+
return Ok(WildcardExpr::QualifiedWildcard(ObjectName(id_parts)));
639+
}
640+
_ => {
641+
return self
642+
.expected("an identifier or a '*' after '.'", next_token);
643+
}
633644
}
634645
}
635646
}
@@ -825,6 +836,9 @@ impl<'a> Parser<'a> {
825836
let next_token = self.next_token();
826837
match next_token.token {
827838
Token::Word(w) => id_parts.push(w.to_ident()),
839+
Token::SingleQuotedString(s) => {
840+
id_parts.push(Ident::with_quote('\'', s))
841+
}
828842
_ => {
829843
return self
830844
.expected("an identifier or a '*' after '.'", next_token);

tests/sqlparser_sqlite.rs

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

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

0 commit comments

Comments
 (0)