Skip to content

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

@ekorchmar

Description

@ekorchmar

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):

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions