From ee93c8df0e5506590185b6986c07fdcba5be7c26 Mon Sep 17 00:00:00 2001 From: Ted Conbeer Date: Thu, 25 Jul 2024 16:14:40 -0600 Subject: [PATCH] fix: parse interval as word operator (#615) --- CHANGELOG.md | 1 + src/sqlfmt/rules/__init__.py | 1 + tests/unit_tests/test_rule.py | 1 + 3 files changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 292a7f2..feaff48 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file. ### Formatting Changes and Bug Fixes - DuckDB's `union [all] by name` is now supported ([#611](https://github.com/tconbeer/sqlfmt/issues/611) - thank you [@aersam](https://github.com/aersam)!). +- `interval` is now parsed as a word operator. Parenthesized expressions like `interval (10) days` will maintain the space after `interval`. ## [0.21.4] - 2024-07-09 diff --git a/src/sqlfmt/rules/__init__.py b/src/sqlfmt/rules/__init__.py index 2c086de..e4eb943 100644 --- a/src/sqlfmt/rules/__init__.py +++ b/src/sqlfmt/rules/__init__.py @@ -49,6 +49,7 @@ r"filter", r"grouping sets", r"(not\s+)?in", + r"interval", r"is(\s+not)?(\s+distinct\s+from)?", r"isnull", r"(not\s+)?i?like(\s+(any|all))?", diff --git a/tests/unit_tests/test_rule.py b/tests/unit_tests/test_rule.py index 742c465..4239d71 100644 --- a/tests/unit_tests/test_rule.py +++ b/tests/unit_tests/test_rule.py @@ -144,6 +144,7 @@ def get_rule(ruleset: List[Rule], rule_name: str) -> Rule: (MAIN, "word_operator", "in"), (MAIN, "word_operator", "not in"), (MAIN, "word_operator", "not\n\nin"), + (MAIN, "word_operator", "interval"), (MAIN, "word_operator", "like"), (MAIN, "word_operator", "not like"), (MAIN, "word_operator", "ilike"),