Support for single-quoted identifiers#1021
Conversation
b36514d to
1cd3035
Compare
This does not support single-quoted table names, but supports the most common case of
select tablename.'column' from tablename
1cd3035 to
e474232
Compare
| Token::SingleQuotedString(s) => { | ||
| id_parts.push(Ident::with_quote('\'', s)) | ||
| } |
There was a problem hiding this comment.
This is the most important part
| 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::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); | ||
| } |
There was a problem hiding this comment.
This we can do later if you want, @alamb , together with support for single-quoted table names.
There was a problem hiding this comment.
I actually tried running the test in this PR without this change and it failed, so I am not quite sure what you are proposing to do later
There was a problem hiding this comment.
This PR supports select 't'.* (which is tested) but not select 't'.my_column.
What I was saying is that if you find that this is not clean, we can remove support for 't'.* (and the associated part of the test) and re-add it later if/when we add general support for single-quoted table names.
There was a problem hiding this comment.
I think it is ok -- thank you
| 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::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); | ||
| } |
There was a problem hiding this comment.
I actually tried running the test in this PR without this change and it failed, so I am not quite sure what you are proposing to do later
|
I took the liberty of merging up from main to resolve a conflict |
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
This does not support single-quoted table names, but supports the most common case of
fixes #1020