Open nakamichiworks opened 1 year ago
This appears to be an interaction with L036 and L042:
$ echo 'with
cte1 as (
select t1.x, t2.y
from tbl1 t1
join (select x, y from tbl2) t2
on t1.x = t2.x
)
, cte2 as (
select x, y from tbl2 t2
)
select x, y from cte1
union all
select x, y from cte2
;' | sqlfluff fix --dialect redshift -
with cte1 as (
select
tbl1.x,
t2.y
from tbl1
inner join t2
on tbl1.x = t2.x
),
cte2 as (
select
x,
y
from tbl2
),
t2 as (select
x,
y
from tbl2)
select
x,
y
from cte1
union all
select
x,
y
from cte2;
But disabling L036:
echo 'with
cte1 as (
select t1.x, t2.y
from tbl1 t1
join (select x, y from tbl2) t2
on t1.x = t2.x
)
, cte2 as (
select x, y from tbl2 t2
)
select x, y from cte1
union all
select x, y from cte2
;' | sqlfluff fix --dialect redshift --exclude-rules L036 -
with t2 as (select x, y from tbl2),
cte1 as (
select tbl1.x, t2.y
from tbl1
inner join t2
on tbl1.x = t2.x
),
cte2 as (
select x, y from tbl2
)
select x, y from cte1
union all
select x, y from cte2;
Search before asking
What Happened
Fixing the rule L042 violation in the following query creates the CTE
t2
in incorrect position, which cannot be referenced from the CTEcte1
sqlfluff fix
sqlfluff fix
Expected Behaviour
t2
should be placed beforecte1
.Observed Behaviour
Described above.
How to reproduce
Described above.
Dialect
Redshift
Version
sqlfluff: 1.4.2 python: 3.10.6
Configuration
Default configuration is used.
Are you willing to work on and submit a PR to address the issue?
Code of Conduct