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

(T-SQL) Bug: Parsing fails when parsing MERGE INTO target (without alias) #5989

Open
2 of 3 tasks
ikarasin opened this issue Jun 28, 2024 · 0 comments
Open
2 of 3 tasks
Labels
bug Something isn't working t-sql Issues related to the T-SQL/TSQL/Transact SQL dialect

Comments

@ikarasin
Copy link

ikarasin commented Jun 28, 2024

Search before asking

  • I searched the issues and found no similar issues.

What Happened

When parsing T-SQL code like:

MERGE INTO dbo.target USING ( SELECT 1 AS i ) AS source ON source.i = target.i WHEN MATCHED THEN UPDATE SET target.i = source.i;

I'm getting parsing error:

L: 1 | P: 2 | PRS | Line 1, Position 2: Found unparsable section: 'MERGE | INTO dbo.target USING \n\t(\tSELECT 1...'

If I add alias to target table, everything is good:

MERGE INTO dbo.target t USING ( SELECT 1 AS i ) AS source ON source.i = target.i WHEN MATCHED THEN UPDATE SET target.i = source.i;

T-SQL dialect supports both options, and I see that in the SQL Fluff code it's configured correctly as well ("Ref("AliasExpressionSegment", optional=True)") in dialect_tsql.py, MergeStatementSegment class.
However, looks like this "optional" value is being ignored in this particular case. If I just delete this "Ref" line - it parses the code well.

Expected Behaviour

No parsing error for this MERGE statement

Observed Behaviour

`L: 1 | P: 2 | PRS | Line 1, Position 2: Found unparsable section: 'MERGE
| INTO dbo.target USING \n\t(\tSELECT 1...'

How to reproduce

run sqlfluff parse --dialect tsql 'script_for_sqlfluff.sql'

script_for_sqlfluff.sql:

MERGE INTO dbo.target USING ( SELECT 1 AS i ) AS source ON source.i = target.i WHEN MATCHED THEN UPDATE SET target.i = source.i;

Dialect

T-SQL

Version

Python 3.11.9, SQL Fluff 3.0.7

Configuration

default config, no extra files

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

@ikarasin ikarasin added the bug Something isn't working label Jun 28, 2024
@github-actions github-actions bot added the t-sql Issues related to the T-SQL/TSQL/Transact SQL dialect label Jun 28, 2024
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

1 participant