Skip to content

Commit

Permalink
TSQL: Allow for table identifier in DELETE clause (#2031)
Browse files Browse the repository at this point in the history
Co-authored-by: jpersons <jpersons@iuhealth.org>
Co-authored-by: Barry Pollard <barry@tunetheweb.com>
  • Loading branch information
3 people committed Dec 4, 2021
1 parent 873a116 commit de50325
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/sqlfluff/dialects/dialect_tsql.py
Expand Up @@ -2162,15 +2162,17 @@ class FileSegment(BaseFileSegment):
class DeleteStatementSegment(BaseSegment):
"""A `DELETE` statement.
DELETE FROM <table name> [ WHERE <search condition> ]
https://docs.microsoft.com/en-us/sql/t-sql/statements/delete-transact-sql?view=sql-server-ver15
Overriding ANSI to remove StartsWith logic which assumes statements have been delimited
and to allow for Azure Synapse Analytics-specific DELETE statements
"""

type = "delete_statement"
# match grammar. This one makes sense in the context of knowing that it's
# definitely a statement, we just don't know what type yet.
match_grammar = Sequence(
"DELETE",
Ref("TableReferenceSegment", optional=True), # Azure Synapse Analytics-specific
Ref("FromClauseSegment"),
Ref("WhereClauseSegment", optional=True),
Ref("DelimiterSegment", optional=True),
Expand Down
@@ -0,0 +1,5 @@
DELETE dbo.Table2
FROM dbo.Table2
INNER JOIN dbo.Table1
ON (dbo.Table2.ColA = dbo.Table1.ColA)
WHERE dboTable2.ColA = 1;
63 changes: 63 additions & 0 deletions test/fixtures/dialects/tsql/delete_azure_synapse_analytics.yml
@@ -0,0 +1,63 @@
# YML test files are auto-generated from SQL files and should not be edited by
# hand. To help enforce this, the "hash" field in the file must match a hash
# computed by SQLFluff when running the tests. Please run
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
# altering SQL files.
_hash: d2c61d379d8c39938482d02df983b8690fa6689e21120deb05d50cc4d810664a
file:
batch:
statement:
delete_statement:
keyword: DELETE
table_reference:
- identifier: dbo
- dot: .
- identifier: Table2
from_clause:
keyword: FROM
from_expression:
from_expression_element:
table_expression:
table_reference:
- identifier: dbo
- dot: .
- identifier: Table2
join_clause:
- keyword: INNER
- keyword: JOIN
- from_expression_element:
table_expression:
table_reference:
- identifier: dbo
- dot: .
- identifier: Table1
- join_on_condition:
keyword: 'ON'
expression:
bracketed:
start_bracket: (
expression:
- column_reference:
- identifier: dbo
- dot: .
- identifier: Table2
- dot: .
- identifier: ColA
- comparison_operator: '='
- column_reference:
- identifier: dbo
- dot: .
- identifier: Table1
- dot: .
- identifier: ColA
end_bracket: )
where_clause:
keyword: WHERE
expression:
column_reference:
- identifier: dboTable2
- dot: .
- identifier: ColA
comparison_operator: '='
literal: '1'
statement_terminator: ;

0 comments on commit de50325

Please sign in to comment.