Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for single-quoted identifiers #1021

Merged
merged 2 commits into from
Oct 24, 2023

Conversation

lovasoa
Copy link
Contributor

@lovasoa lovasoa commented Oct 23, 2023

This does not support single-quoted table names, but supports the most common case of

select tablename.'column' from tablename

fixes #1020

This does not support single-quoted table names, but supports the most common case of

    select tablename.'column' from tablename
Comment on lines +839 to +841
Token::SingleQuotedString(s) => {
id_parts.push(Ident::with_quote('\'', s))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most important part

Comment on lines +621 to +643
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);
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This we can do later if you want, @alamb , together with support for single-quoted table names.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@alamb

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.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it is ok -- thank you

Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good to me @lovasoa -- thank you. I had one question about your comment but otherwise I think this is ready to go

Comment on lines +621 to +643
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);
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@alamb
Copy link
Contributor

alamb commented Oct 24, 2023

I took the liberty of merging up from main to resolve a conflict

@alamb alamb changed the title add support for single-quoted identifiers Support for single-quoted identifiers Oct 24, 2023
@alamb alamb merged commit c5a7d6c into apache:main Oct 24, 2023
10 checks passed
serprex pushed a commit to serprex/sqlparser-rs that referenced this pull request Nov 6, 2023
Co-authored-by: Andrew Lamb <andrew@nerdnetworks.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

support SQLite single-quoted identifiers
2 participants