Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sql "is [not] distinct from" expressions are incorrectly split by "from" #327

Closed
IgnorantWalking opened this issue Nov 24, 2022 · 6 comments
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@IgnorantWalking
Copy link

Describe the bug
When formatting a "is [not] distinct from" SQL expression (postgreSQL snowflake), the library seems to look for the "from" part and uses it to split the expression into multiple lines, even when exists enough horizontal spaces to keep the expression untouched.

To Reproduce
Example input expression:

select foo, bar, baz
from dual
where foo is not distinct from baz or bar is distinct from baz

Expected behavior
The "is [not] distinct from" expressions should be kept in a single line:

select foo, bar, baz
from dual
where foo is not distinct from baz 
or bar is distinct from baz

Actual behavior

select foo, bar, baz
from dual
where foo is not distinct
from baz or bar is distinct
from baz

Additional context
tested with sqlfmt v0.13.0

Many, many thanks for the library!! Even in the current early stage is a really useful tool for us!

@tconbeer
Copy link
Owner

Thanks for the report. Never heard of "is distinct from" before. Will be an easy add.

@kxzk
Copy link
Contributor

kxzk commented Nov 28, 2022

@tconbeer If you're open to it, I'm happy to work on implementing this. Seems like a simple add to Rule(name="word_operator", ...) in sqlfmt/rules/__init__.py.

Let me know!

@tconbeer
Copy link
Owner

Yes, exactly! And add tests, please!

@tconbeer tconbeer added enhancement New feature or request good first issue Good for newcomers labels Nov 28, 2022
@kxzk
Copy link
Contributor

kxzk commented Nov 30, 2022

@tconbeer lost on step 3 from here - don't see any unformatted tag, thus can't checkout branch. What am I missing?

@tconbeer
Copy link
Owner

Don't worry about updating the primer -- you probably don't need to for this change. Please just open a PR and it'll run in CI. I'll help you with primer changes if necessary

kxzk added a commit to kxzk/sqlfmt that referenced this issue Nov 30, 2022
kxzk added a commit to kxzk/sqlfmt that referenced this issue Dec 1, 2022
kxzk added a commit to kxzk/sqlfmt that referenced this issue Dec 1, 2022
@tconbeer
Copy link
Owner

tconbeer commented Dec 1, 2022

closed by #332

@tconbeer tconbeer closed this as completed Dec 1, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants