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

T-SQL: Explicit aliasing of columns broken when using = #2749

Closed
3 tasks done
fdw opened this issue Mar 1, 2022 · 4 comments · Fixed by #2750
Closed
3 tasks done

T-SQL: Explicit aliasing of columns broken when using = #2749

fdw opened this issue Mar 1, 2022 · 4 comments · Fixed by #2750
Labels
bug Something isn't working

Comments

@fdw
Copy link
Contributor

fdw commented Mar 1, 2022

Search before asking

  • I searched the issues and found no similar issues.

What Happened

I fear #2727 broke something.
Take this example:

select key = value
from table

With L012 set to explicit aliases, the result is invalid SQL:

select as key = value
from table

Instead, I would expect

select value as key
from table

or (preferably)

select key = value
from table

Expected Behaviour

See above: Not broken code, either using as or = but not both ;)

Observed Behaviour

sqlfluff currently adds an as, but also keeps the aliasing with =.

How to reproduce

See above: Use that snippet and call sqlfluff fix on it.

Dialect

T-SQL

Version

Current master

Configuration

[sqlfluff]
dialect = tsql

[sqlfluff:rules:L011] # Aliasing
aliasing = implicit

[sqlfluff:rules:L012] # Aliasing
aliasing = explicit

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

@fdw fdw added the bug Something isn't working label Mar 1, 2022
@tunetheweb
Copy link
Member

Yes I really think L012 is currently incompatible with this usage of aliasing. So think it needs to be turned off.

But concerning it corrupts SQL if people don't realise that. Would be good to update L012 to ignore this aliasing before 0.11.0 to avoid that issue.

@tunetheweb
Copy link
Member

I get linting errors with your examples. key, value and table are not valid sql.

@tunetheweb
Copy link
Member

Managed to fix it in #2750

@fdw
Copy link
Contributor Author

fdw commented Mar 1, 2022

Awesome, 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
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants