-
-
Notifications
You must be signed in to change notification settings - Fork 873
Closed
Labels
Description
Search before asking
- I searched the issues and found no similar issues.
What Happened
A parsing error is thrown when linting a statement that uses a PIVOT clause when the aggregate function is aliased. If no alias is used, the file parses successfully.
Expected Behaviour
The file should parse correctly.
Observed Behaviour
Parsing error is thrown instead:
== [broken_pivot.sql] FAIL
L: 7 | P: 1 | PRS | Line 7, Position 1: Found unparsable section:
| 'pivot\n(\n count(state_code) as states\n...'
WARNING: Parsing errors found and dialect is set to 'oracle'. Have you configured your dialect correctly?
How to reproduce
-- broken_pivot.sql
select * from (
select
times_purchased,
state_code
from customers
)
pivot
(
count(state_code) as states
for state_code in ('NY' as new_york, 'CT', 'NJ', 'FL', 'MO')
);
-- working_pivot.sql
select * from (
select
times_purchased,
state_code
from customers
)
pivot
(
count(state_code)
for state_code in ('NY' as new_york, 'CT', 'NJ', 'FL', 'MO')
);
The only difference between the two files is the count(state_code)
line. One is aliased the other not.
$ sqlfluff lint working_pivot.sql broken_pivot.sql
I think the problem lies here:
sqlfluff/src/sqlfluff/dialects/dialect_oracle.py
Lines 934 to 936 in 1d3a0f0
Delimited( | |
Ref("FunctionSegment"), Ref("AliasExpressionSegment", optional=True) | |
), |
Maybe a missing Sequence?
Dialect
oracle
Version
3.3.1
Configuration
[sqlfluff]
dialect = oracle
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
- I agree to follow this project's Code of Conduct