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

tsql: delete/insert/update tbl output deleted.id unparseable when wrapped #3487

Open
3 tasks done
ReinierKop opened this issue Jun 23, 2022 · 0 comments
Open
3 tasks done
Labels
bug Something isn't working t-sql Issues related to the T-SQL/TSQL/Transact SQL dialect

Comments

@ReinierKop
Copy link

ReinierKop commented Jun 23, 2022

Search before asking

  • I searched the issues and found no similar issues.

What Happened

I ran sqlfluff parse output.sql --dialect tsql on a file containing valid tsql with output segment logic and it did not parse.

Expected Behaviour

I expect the segments to parse using the tsql dialect

Observed Behaviour

The segments are not correctly parsed by sqlfluff

How to reproduce

The following pieces of tsql code are valid but unparseable.

Delete example:

insert into tbl1
select id from (
    delete tbl2
    output deleted.id
) as x

Update example:

insert into tbl1
select id from (
    update tbl2 
    set id=2
    output inserted.id
) as x

Insert example:

insert into tbl1
select id from (
    insert into tbl2 
    output inserted.id
    select 1 as id
) as x

After a bit of digging, I suspect the issue lies with this piece of code which distinguishes selects from inserts/updates/deletes. For tsql, that logic breaks down whenever you add an output segment to these i/u/d segments, since adding that optional segment effectively transforms the entire segment into something "selectable" in tsql.

I'm happy to work on a potential fix but hard-pressed for ideas on how to proceed from here; I suspect it may require some more advanced logic to get this to work that I'm not familiar with yet.

Dialect

tsql

Version

sqlfluff v1.0.0
python v3.10.5

Configuration

default config

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

@ReinierKop ReinierKop added the bug Something isn't working label Jun 23, 2022
@tunetheweb tunetheweb added the t-sql Issues related to the T-SQL/TSQL/Transact SQL dialect label Jun 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working t-sql Issues related to the T-SQL/TSQL/Transact SQL dialect
Projects
None yet
Development

No branches or pull requests

2 participants