tconbeer / sqlfmt

sqlfmt formats your dbt SQL files so you don't have to
https://sqlfmt.com
Apache License 2.0
364 stars 15 forks source link

exists inside select when select items are on separate lines #602

Open roveo opened 3 weeks ago

roveo commented 3 weeks ago

Describe the bug

When exists clause is used as a column inside select clause, it's put on the same line as the previous column, even when formatter decided to put each column on a separate line.

My thinking is that conceptually exists is a function, the only thing that's special about it is that it has a query as its argument.

To Reproduce

Here's an example (already formatted):

select
    foo as bar, exists (select 1 from baz where qux = quux) as foo1,
    case when something then this else also end as more
from bar1

Expected behavior

select
    foo as bar,
    exists (select 1 from baz where qux = quux) as foo1,
    case when something then this else also end as more
from bar1

Additional context

sqlfmt, version 0.21.3

What is the output of pip list (or pipx list if you installed using pipx)?

Package               Version      Editable project location
--------------------- ------------ -----------------------------------------
antlr4-tools          0.2
appdirs               1.4.4
attrs                 23.1.0
audioread             3.0.1
black                 23.11.0
cattrs                23.2.3
certifi               2023.7.22
cffi                  1.16.0
chardet               5.2.0
charset-normalizer    3.3.0
click                 8.1.7
colorama              0.4.6
contourpy             1.1.1
cycler                0.12.1
decorator             5.1.1
diff_cover            8.0.1
diskcache             5.6.3
docstring-to-markdown 0.13
duckdb                0.9.2
et-xmlfile            1.1.0
fingerprinting        1.0          /Users/roveo/proj/project2/fingerprinting
fonttools             4.43.1
greenlet              3.0.1
gTTS                  2.3.2
idna                  3.4
iniconfig             2.0.0
install-jdk           1.1.0
isort                 5.12.0
jedi                  0.19.1
jedi-language-server  0.41.2
Jinja2                3.1.2
joblib                1.3.2
kiwisolver            1.4.5
lazy_loader           0.3
librosa               0.10.1
llvmlite              0.41.1
lsprotocol            2023.0.0
MarkupSafe            2.1.3
matplotlib            3.8.0
msgpack               1.0.7
mypy-extensions       1.0.0
neovim                0.3.1
numba                 0.58.1
numpy                 1.26.0
openpyxl              3.1.2
packaging             23.2
pandas                2.1.1
parso                 0.8.3
pathspec              0.11.2
Pillow                10.1.0
pip                   24.0
platformdirs          3.11.0
pluggy                1.3.0
pooch                 1.7.0
PyBindGen             0.22.1
pycparser             2.21
pydub                 0.25.1
pygls                 1.2.1
Pygments              2.17.2
pynvim                0.5.0
pyparsing             3.1.1
pytest                7.4.3
python-dateutil       2.8.2
python-lsp-jsonrpc    1.1.2
python-lsp-ruff       2.0.0
python-lsp-server     1.9.0
pytz                  2023.3.post1
PyYAML                6.0.1
regex                 2023.10.3
requests              2.31.0
ruff                  0.1.8
ruff-lsp              0.0.47
scikit-learn          1.3.1
scipy                 1.11.3
setuptools            70.0.0
shandy-sqlfmt         0.21.3
six                   1.16.0
soundfile             0.12.1
soxr                  0.3.7
sqlfluff              2.3.5
tblib                 3.0.0
threadpoolctl         3.2.0
tqdm                  4.66.1
typer                 0.9.0
typing_extensions     4.8.0
tzdata                2023.3
ujson                 5.9.0
urllib3               2.0.6
wheel                 0.43.0