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

Snowflake, Postgres: Parse failure on concatention operator || #4164

Closed
2 of 3 tasks
ixti opened this issue Dec 14, 2022 · 9 comments · Fixed by #4168
Closed
2 of 3 tasks

Snowflake, Postgres: Parse failure on concatention operator || #4164

ixti opened this issue Dec 14, 2022 · 9 comments · Fixed by #4168
Labels
bug Something isn't working postgres Issues relating to the Postgres dialect snowflake Issues related to the Snowflake dialect

Comments

@ixti
Copy link

ixti commented Dec 14, 2022

Search before asking

  • I searched the issues and found no similar issues.

What Happened

Concatenate operand || incorrectly parsed as two pipes. Both Snowflake and Postgres recognize || as concatenation operand, thus 'a' || 'b' -- => 'ab'. SQLFluff blames it's incorrect syntax.

Expected Behaviour

'a' || 'b' should pass linting

Observed Behaviour

'a' || 'b' fails linting with:

Expected single whitespace between pipe '|' and pipe '|'.

How to reproduce

echo "SELECT 'a' || 'b' AS c;" | sqlfluff lint --dialect postgres --disable-progress-bar -
echo "SELECT 'a' || 'b' AS c;" | sqlfluff lint --dialect snowflake --disable-progress-bar -

Dialect

Snowflake
Postgres

Version

sqlfluff, version 1.4.3
Python 3.10.9

Configuration

[sqlfluff]
templater = jinja

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

Code of Conduct

@ixti ixti added the bug Something isn't working label Dec 14, 2022
@barrywhart barrywhart changed the title Fails on concatention operator || for no real reason Snowflake, Postgres: Parse failure on concatention operator || Dec 14, 2022
@barrywhart barrywhart added postgres Issues relating to the Postgres dialect snowflake Issues related to the Snowflake dialect labels Dec 14, 2022
@barrywhart
Copy link
Member

"For no real reason"?

@ixti
Copy link
Author

ixti commented Dec 14, 2022

@barrywhart

"For no real reason"?

I meant it fails when it should not (on a valid syntax). Didn't mean to offend or being rude. :D Coming from my initial assumption that SQLs I've been linting were broken. :D

@ixti
Copy link
Author

ixti commented Dec 14, 2022

The bug is reproducable in v1.4.3; v1.4.2 is unaffected.

@dondupont
Copy link

I am experiencing this as well. The double pipe concatenation operator is being split into two and is causing the query to fail during execution.

@kyanscienceman
Copy link

Experiencing this as well in BigQuery. Looks like | and ||are both valid BigQuery operators, so makes sense why it's happening, though I'm not sure why this only started being an issue in v1.4.3. For now we disabled L006 in our repo as a workaround.

@tunetheweb
Copy link
Member

Just go this too. Submitting a fix.

@tunetheweb
Copy link
Member

FYI adding this to your config fixes it:

[sqlfluff:layout:type:binary_operator]
spacing_within = touch

We're adding it to the default config in #4168 and releasing another fix tonight, but if you can't wait then apply above addition to your config.

@tunetheweb
Copy link
Member

SQLFluff 1.4.4 has been released with this fixed in it.

Apologies!

@ixti
Copy link
Author

ixti commented Dec 15, 2022

@tunetheweb thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working postgres Issues relating to the Postgres dialect snowflake Issues related to the Snowflake dialect
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants