Skip to content

Commit

Permalink
TSQL: CTAS delimiter (#1652)
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 authored and CyberShadow committed Oct 14, 2021
1 parent 1bba945 commit 27d1610
Show file tree
Hide file tree
Showing 3 changed files with 139 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/sqlfluff/dialects/dialect_tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,7 @@ class CreateTableAsSelectStatementSegment(BaseSegment):
Ref("TableDistributionIndexClause"),
"AS",
Ref("SelectableGrammar"),
Ref("DelimiterSegment", optional=True),
)


Expand Down
17 changes: 17 additions & 0 deletions test/fixtures/dialects/tsql/create_table_as_select.sql
Original file line number Diff line number Diff line change
@@ -1,4 +1,20 @@
--Azure Synapse Analytics specific
CREATE TABLE [dbo].[PL_stage]
WITH (DISTRIBUTION = HASH([ID]), HEAP)
AS
SELECT e.[ID]
,e.[ArriveDate]
,e.[Contribution]
,e.[DischargeDate]
,e.[Encounter]
,e.[Facility]
,e.[Region]
,e.[LOS]
FROM dbo.Encounter e
JOIN dbo.Finance f ON e.[ID] = f.[ID];

DROP TABLE [dbo].[PL_stage];

CREATE TABLE [dbo].[PL_stage]
WITH (DISTRIBUTION = HASH([ID]), HEAP)
AS
Expand All @@ -12,3 +28,4 @@ SELECT e.[ID]
,e.[LOS]
FROM dbo.Encounter e
JOIN dbo.Finance f ON e.[ID] = f.[ID]

123 changes: 121 additions & 2 deletions test/fixtures/dialects/tsql/create_table_as_select.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,129 @@
# 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: 67a0dff78a2824a7e81e9a0b912a2111f64d10b882b21400a7943c99d7b8ed54
_hash: c933bf51a41bc8c869bfa4159032060e355b4ce8428a1bc7a898ce68a92e1bfd
file:
batch:
statement:
- statement:
create_table_as_select_statement:
- keyword: CREATE
- keyword: TABLE
- table_reference:
- identifier: '[dbo]'
- dot: .
- identifier: '[PL_stage]'
- table_distribution_index_clause:
keyword: WITH
bracketed:
start_bracket: (
table_distribution_clause:
- keyword: DISTRIBUTION
- comparison_operator: '='
- keyword: HASH
- bracketed:
start_bracket: (
column_reference:
identifier: '[ID]'
end_bracket: )
comma: ','
table_index_clause:
keyword: HEAP
end_bracket: )
- keyword: AS
- select_statement:
select_clause:
- keyword: SELECT
- select_clause_element:
column_reference:
- identifier: e
- dot: .
- identifier: '[ID]'
- comma: ','
- select_clause_element:
column_reference:
- identifier: e
- dot: .
- identifier: '[ArriveDate]'
- comma: ','
- select_clause_element:
column_reference:
- identifier: e
- dot: .
- identifier: '[Contribution]'
- comma: ','
- select_clause_element:
column_reference:
- identifier: e
- dot: .
- identifier: '[DischargeDate]'
- comma: ','
- select_clause_element:
column_reference:
- identifier: e
- dot: .
- identifier: '[Encounter]'
- comma: ','
- select_clause_element:
column_reference:
- identifier: e
- dot: .
- identifier: '[Facility]'
- comma: ','
- select_clause_element:
column_reference:
- identifier: e
- dot: .
- identifier: '[Region]'
- comma: ','
- select_clause_element:
column_reference:
- identifier: e
- dot: .
- identifier: '[LOS]'
from_clause:
keyword: FROM
from_expression:
from_expression_element:
table_expression:
table_reference:
- identifier: dbo
- dot: .
- identifier: Encounter
alias_expression:
identifier: e
join_clause:
keyword: JOIN
from_expression_element:
table_expression:
table_reference:
- identifier: dbo
- dot: .
- identifier: Finance
alias_expression:
identifier: f
join_on_condition:
keyword: 'ON'
expression:
- column_reference:
- identifier: e
- dot: .
- identifier: '[ID]'
- comparison_operator: '='
- column_reference:
- identifier: f
- dot: .
- identifier: '[ID]'
statement_terminator: ;
- statement:
drop_statement:
- keyword: DROP
- keyword: TABLE
- table_reference:
- identifier: '[dbo]'
- dot: .
- identifier: '[PL_stage]'
- statement_terminator: ;
- statement:
create_table_as_select_statement:
- keyword: CREATE
- keyword: TABLE
Expand Down

0 comments on commit 27d1610

Please sign in to comment.