diff --git a/CHANGELOG.md b/CHANGELOG.md index 42bde94b..f13d87f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. ## [Unreleased] +### Bug Fixes + +- The Postgres operators for `(NOT) (I)LIKE`, `~~`, `~~*`, `!~~`, `!~~*`, are now supported (these use two tildes where the posix version of these operators use a single tilde) ([#576](https://github.com/tconbeer/sqlfmt/issues/576) - thank you [@tuckerrc](https://github.com/tuckerrc)!). + ## [0.21.2] - 2024-01-22 ### Bug Fixes diff --git a/src/sqlfmt/operator_precedence.py b/src/sqlfmt/operator_precedence.py index 22f4b426..10747e0e 100644 --- a/src/sqlfmt/operator_precedence.py +++ b/src/sqlfmt/operator_precedence.py @@ -79,6 +79,10 @@ def _from_operator(node: Node) -> "OperatorPrecedence": "~*": OperatorPrecedence.MEMBERSHIP, "!~": OperatorPrecedence.MEMBERSHIP, "!~*": OperatorPrecedence.MEMBERSHIP, + "~~": OperatorPrecedence.MEMBERSHIP, + "~~*": OperatorPrecedence.MEMBERSHIP, + "!~~": OperatorPrecedence.MEMBERSHIP, + "!~~*": OperatorPrecedence.MEMBERSHIP, } return value_mapping.get(node.value, OperatorPrecedence.OTHER) diff --git a/src/sqlfmt/rules/core.py b/src/sqlfmt/rules/core.py index a06e9bd8..92ddb9d9 100644 --- a/src/sqlfmt/rules/core.py +++ b/src/sqlfmt/rules/core.py @@ -163,7 +163,7 @@ pattern=group( r"\|\|?\/", # square or cube root ||/ r"~=", # geo compare - r"!?~\*?", # posix like/not like + r"!?~{1,2}\*?", # posix like/not like r"\?(=|!|<=| Rule: (CORE, "operator", "!~"), (CORE, "operator", "~*"), (CORE, "operator", "!~*"), + # postgres (not) like/ilike operators + # like posix but doubles the tilde + # https://github.com/tconbeer/sqlfmt/issues/576 + (CORE, "operator", "~~"), + (CORE, "operator", "!~~"), + (CORE, "operator", "~~*"), + (CORE, "operator", "!~~*"), # postgresql geo operators # see: https://www.postgresql.org/docs/current/functions-geometry.html (CORE, "operator", "@-@"),