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

Linting doesn't work over plpgsql blocks #5864

Open
2 of 3 tasks
galhar opened this issue May 10, 2024 · 1 comment
Open
2 of 3 tasks

Linting doesn't work over plpgsql blocks #5864

galhar opened this issue May 10, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@galhar
Copy link

galhar commented May 10, 2024

Search before asking

  • I searched the issues and found no similar issues.

What Happened

I really want to use sqlfluff in my system contains multiple, big sql files running over greenplum.
The problem is that many of my sql files contain plpgsql blocks, and sqlfluff seems to not work when being run over such files.

Expected Behaviour

Running lint should yield errors, running fix should fix the file. When running over the following code of plpgsql block:

do
$$
declare 
  v1 INTEGER;
begin
  create temp table bla3 as
  with bla1 as (select generate_series(0,100,1) as x1
  ),
  bla2 as (
        select x1, x1*2 as x2
                 from bla1
  )
  select 
    bla1.x1, bla2.x2,
         bla2.x2 * bla1.x1 as x3
  from bla2
inner join bla1
    on true;
  analyze bla3;
  
  raise info 'max is %', (select max(x3) from bla3);  
 
end;
$$
language plpgsql;

We expect sqlfluff to work the same way it would work over the same code out of the plpgsql block:

create temp table bla3 as
  with bla1 as (select generate_series(0,100,1) as x1
  ),
  bla2 as (
        select x1, x1*2 as x2
                 from bla1
  )
  select 
    bla1.x1, bla2.x2,
         bla2.x2 * bla1.x1 as x3
  from bla2
inner join bla1
    on true;
  analyze bla3;

Observed Behaviour

But I get the following results when fixing:
The plpgsql remains exactly the same:

do
$$
declare 
  v1 INTEGER;
begin
  create temp table bla3 as
  with bla1 as (select generate_series(0,100,1) as x1
  ),
  bla2 as (
        select x1, x1*2 as x2
                 from bla1
  )
  select 
    bla1.x1, bla2.x2,
         bla2.x2 * bla1.x1 as x3
  from bla2
inner join bla1
    on true;
  analyze bla3;
  
  raise info 'max is %', (select max(x3) from bla3);  
 
end;
$$
language plpgsql;

whereas the same code not within such a block get fixed as desired:

create temp table bla3 as
with bla1 as (select generate_series(0, 100, 1) as x1
),

bla2 as (
    select
        x1,
        x1 * 2 as x2
    from bla1
)

select
    bla1.x1,
    bla2.x2,
    bla2.x2 * bla1.x1 as x3
from bla2
inner join bla1
    on true;
analyze bla3;

How to reproduce

Just run sqlfluff fix example.sql --dialect greenplum, when the example.sql file contains either one of the code blocks wrote above.

Dialect

greenplum

Version

3.0.6

Configuration

default, no configuration file needed

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

@galhar galhar added the bug Something isn't working label May 10, 2024
@galhar
Copy link
Author

galhar commented May 10, 2024

I might be wrongly labelling it as "bug", if it isn't supported by purpose. But it seems like Sqlfluff should support postgresql and greenplum.

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

No branches or pull requests

1 participant