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

tsql: code corruption alias removed L025 #3547

Closed
2 of 3 tasks
fmms opened this issue Jul 3, 2022 · 1 comment · Fixed by #3548
Closed
2 of 3 tasks

tsql: code corruption alias removed L025 #3547

fmms opened this issue Jul 3, 2022 · 1 comment · Fixed by #3548
Assignees
Labels
bug Something isn't working

Comments

@fmms
Copy link
Contributor

fmms commented Jul 3, 2022

Search before asking

  • I searched the issues and found no similar issues.

What Happened

I have the following query

SELECT * FROM (
        SELECT col FROM dbo.tab
        UNION
        SELECT -1 AS col
) AS a

I tried to format that.

Expected Behaviour

Query is formatted and still executable.

Observed Behaviour

Query broken.

How to reproduce

PS > cat .\sqlfluff-9.config
[sqlfluff]
dialect = tsql
templater = raw
PS > cat .\sqlfluff-9.sql
SELECT * FROM (
        SELECT col FROM dbo.tab
        UNION
        SELECT -1 AS col
) AS a
PS > sqlfluff fix .\sqlfluff-9.sql --config .\sqlfluff-9.config
==== finding fixable violations ====
== [sqlfluff-9.sql] FAIL
L:   5 | P:   6 | L025 | Alias 'a' is never used in SELECT statement.
==== fixing violations ====
1 fixable linting violations found
Are you sure you wish to attempt to fix these? [Y/n]

Dialect

tsql

Version

current git

Configuration

see above

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

@fmms fmms added the bug Something isn't working label Jul 3, 2022
@barrywhart
Copy link
Member

Got it -- I bet I need to check for a different segment type, because using UNION wraps the select_statement in a surrounding segment type. I can probably fix it this morning, not sure if I can get a reviewer before we release 1.1.0 today.

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