Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion sqlparse/keywords.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
tokens.Keyword),
(r"(AT|WITH')\s+TIME\s+ZONE\s+'[^']+'", tokens.Keyword.TZCast),
(r'(NOT\s+)?(LIKE|ILIKE|RLIKE)\b', tokens.Operator.Comparison),
(r'(NOT\s+)?(REGEXP)\b', tokens.Operator.Comparison),
(r'(NOT\s+)?(REGEXP)(\s+(BINARY))?\b', tokens.Operator.Comparison),
# Check for keywords, also returns tokens.Name if regex matches
# but the match isn't a keyword.
(r'\w[$#\w]*', PROCESS_AS_KEYWORD),
Expand Down
30 changes: 30 additions & 0 deletions tests/test_parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,36 @@ def test_configurable_keywords():
]


def test_regexp():
s = "column REGEXP '.+static.+'"
stmts = sqlparse.parse(s)

assert len(stmts) == 1
assert stmts[0].tokens[0].ttype == T.Keyword
assert stmts[0].tokens[0].value == "column"

assert stmts[0].tokens[2].ttype == T.Comparison
assert stmts[0].tokens[2].value == "REGEXP"

assert stmts[0].tokens[4].ttype == T.Literal.String.Single
assert stmts[0].tokens[4].value == "'.+static.+'"


def test_regexp_binary():
s = "column REGEXP BINARY '.+static.+'"
stmts = sqlparse.parse(s)

assert len(stmts) == 1
assert stmts[0].tokens[0].ttype == T.Keyword
assert stmts[0].tokens[0].value == "column"

assert stmts[0].tokens[2].ttype == T.Comparison
assert stmts[0].tokens[2].value == "REGEXP BINARY"

assert stmts[0].tokens[4].ttype == T.Literal.String.Single
assert stmts[0].tokens[4].value == "'.+static.+'"


def test_configurable_regex():
lex = Lexer.get_default_instance()
lex.clear()
Expand Down
Loading