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: CTAS delimiter #1652

Merged
merged 2 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/sqlfluff/dialects/dialect_tsql.py
Original file line number Diff line number Diff line change
Expand Up @@ -1143,6 +1143,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