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

Allow no alias for selects in CTEs with a column list #3580

Merged

Conversation

pdebelak
Copy link
Contributor

@pdebelak pdebelak commented Jul 9, 2022

Brief summary of the change made

In cases where the CTE has a column list, we don't need an alias for columns. This checks if the select has a common_table_expression parent and if that parent has a cte_column_list child. In that case, it doesn't complain about a missing alias.

Fixes #3558

Are there any other side effects of this change that we should be aware of?

I'm not 100% positive that this won't lead to false negatives in some weirdly nested situation. Open to feedback there.

Also, I'm not sure if this rule should be checking if the number of items in the cte_column_list matches the number of selects. It seems like that is out of scope for this rule (since it probably means that you have a syntax error), but I could be wrong.

Pull Request checklist

  • Please confirm you have completed any of the necessary steps below.

  • Included test cases to demonstrate any code changes, which may be one or more of the following:

    • .yml rule test cases in test/fixtures/rules/std_rule_cases.
    • .sql/.yml parser test cases in test/fixtures/dialects (note YML files can be auto generated with tox -e generate-fixture-yml).
    • Full autofix test cases in test/fixtures/linter/autofix.
    • Other.
  • Added appropriate documentation for the change.

  • Created GitHub issues for any relevant followup/future enhancements if appropriate.

In cases where the CTE has a column list, we don't need an alias for
columns. This checks if the select has a `common_table_expression`
parent and if that parent has a `cte_column_list` child. In that case,
it doesn't complain about a missing alias.

Fixes sqlfluff#3558
@codecov
Copy link

codecov bot commented Jul 9, 2022

Codecov Report

Merging #3580 (320b268) into main (ac8dd5f) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##              main     #3580   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          174       174           
  Lines        13140     13144    +4     
=========================================
+ Hits         13140     13144    +4     
Impacted Files Coverage Δ
src/sqlfluff/rules/L013.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ac8dd5f...320b268. Read the comment docs.

Copy link
Member

@barrywhart barrywhart left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work!

I agree that we don't need to check the number of column names in the list.

@barrywhart barrywhart merged commit 50f0638 into sqlfluff:main Jul 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[postgres] Complaining about missing alias in CTE
2 participants