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

Token.match special behavior for keywords should be optional #795

Open
ekorchmar opened this issue Nov 7, 2024 · 1 comment
Open

Token.match special behavior for keywords should be optional #795

ekorchmar opened this issue Nov 7, 2024 · 1 comment

Comments

@ekorchmar
Copy link

Is your feature request related to a problem? Please describe.
In current date and age, most DB engines do not care if any of the tokens are upper or lower case. One could argue that it is a good practice to keep keywords uppercase for readability, but sqlparse should not attempt to be an opinionated linter.

I need to detect "SELECT foo FROM bar INTO baz" statements, which is a quirky replacement for CREATE TABLE AS SELECT in MS SQL Server. I cannot use Token.match for this, however: I would need to explicitly list every single combination of uppercase and lowercase letters in SELECT (Select, select, etc.) if I wanted to use this method. This is 64 possible combinations. Not doing this.

Describe the solution you'd like
An additional parameter (can still default to existing behavior) to allow case ignore when matching Keyword tokens.

Describe alternatives you've considered
Monkey patching my own function

Relevant doc page:
https://sqlparse.readthedocs.io/en/0.1.3/analyzing/#sqlparse.sql.Token.match
Relevant code:

def match(self, ttype, values, regex=False):

@ekorchmar
Copy link
Author

Ok, so after reading the code, I now see that behavior is actually exactly what I need it to be – but documentation is borderline unreadable. Submitting a PR to update it and to make ignore-case behavior configurable.

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

No branches or pull requests

1 participant