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

[postgres] Complaining about missing alias in CTE #3558

Closed
2 of 3 tasks
enote-kane opened this issue Jul 5, 2022 · 5 comments · Fixed by #3580
Closed
2 of 3 tasks

[postgres] Complaining about missing alias in CTE #3558

enote-kane opened this issue Jul 5, 2022 · 5 comments · Fixed by #3580
Labels
awaiting feedback Cannot continue investigating until more information is provided. bug Something isn't working

Comments

@enote-kane
Copy link

Search before asking

  • I searched the issues and found no similar issues.

What Happened

Linting errors raised where no errors are expected

Expected Behaviour

No errors.

Observed Behaviour

$ sqlfluff lint --nocolor --verbose --dialect postgres 2022-07-05.cte-column-alias.sql 
==== sqlfluff ====
sqlfluff:                1.1.0 python:                 3.8.10
implementation:        cpython verbosity:                   1
dialect:              postgres templater:               jinja
rules:                                all
==== readout ====

=== [ path: 2022-07-05.cte-column-alias.sql ] ===

== [2022-07-05.cte-column-alias.sql] FAIL                                                                                                                                         
L:   2 | P:  15 | L022 | Blank line expected but not found after CTE closing
                       | bracket.
L:   5 | P:   9 | L013 | Column expression without alias. Use explicit `AS`
                       | clause.
L:   6 | P:   9 | L013 | Column expression without alias. Use explicit `AS`
                       | clause.
==== summary ====
violations:        3 status:         FAIL
All Finished!

While also (still) raising issue #3474, it also complains about the missing alias as soon as one uses a non-column/non-constant expression.

How to reproduce

Use the following 2022-07-05.cte-column-alias.sql file:

WITH
cte (a, b, c) AS (
    SELECT
        column_a,
        min(column_b),
        sum(column_c)
    FROM my_table
    GROUP BY 1
)

SELECT
    a,
    b,
    c
FROM cte;

Dialect

postgres

Version

sqlfluff:                1.1.0 python:                 3.8.10
implementation:        cpython verbosity:                   1
dialect:              postgres templater:               jinja
rules:                                all

Configuration

defaults

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

@enote-kane enote-kane added the bug Something isn't working label Jul 5, 2022
@barrywhart
Copy link
Member

We merged a PR a couple days ago which may have fixed this.

@barrywhart
Copy link
Member

This is not a bug. L013 is working as designed: It wants computed columns to have aliases. Why do you think this is a bug?

@barrywhart barrywhart added the awaiting feedback Cannot continue investigating until more information is provided. label Jul 8, 2022
@tunetheweb
Copy link
Member

It could be argued the computer columns have aliases here (a, b, c).

@tunetheweb
Copy link
Member

Then again it could also be argued a more explicit alias within the select query itself would be more useful (e.g. it could be used in order by or group by queries).

@barrywhart
Copy link
Member

That's true -- a different form of alias. I'm inclined to call this an enhancement rather than a bug.

pdebelak added a commit to pdebelak/sqlfluff that referenced this issue Jul 9, 2022
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
pdebelak added a commit to pdebelak/sqlfluff that referenced this issue Jul 9, 2022
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
pdebelak added a commit to pdebelak/sqlfluff that referenced this issue Jul 9, 2022
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
barrywhart pushed a commit that referenced this issue Jul 9, 2022
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting feedback Cannot continue investigating until more information is provided. bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants