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

Add DROP TYPE statement to ANSI dialect #1919

Merged
merged 3 commits into from Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 15 additions & 0 deletions src/sqlfluff/dialects/dialect_ansi.py
Expand Up @@ -2268,6 +2268,20 @@ class DropSchemaStatementSegment(BaseSegment):
)


@ansi_dialect.segment()
class DropTypeStatementSegment(BaseSegment):
"""A `DROP TYPE` statement."""

type = "drop_type_statement"
match_grammar = Sequence(
"DROP",
"TYPE",
Ref("IfExistsGrammar", optional=True),
Ref("ObjectReferenceSegment"),
OneOf("RESTRICT", "CASCADE", optional=True),
)


@ansi_dialect.segment()
class CreateDatabaseStatementSegment(BaseSegment):
"""A `CREATE DATABASE` statement."""
Expand Down Expand Up @@ -2960,6 +2974,7 @@ class StatementSegment(BaseSegment):
Ref("CreateSchemaStatementSegment"),
Ref("SetSchemaStatementSegment"),
Ref("DropSchemaStatementSegment"),
Ref("DropTypeStatementSegment"),
Ref("CreateDatabaseStatementSegment"),
Ref("CreateExtensionStatementSegment"),
Ref("CreateIndexStatementSegment"),
Expand Down
3 changes: 1 addition & 2 deletions src/sqlfluff/dialects/dialect_postgres.py
Expand Up @@ -2140,7 +2140,6 @@ class StatementSegment(BaseSegment):
Ref("AnalyzeStatementSegment"),
Ref("CreateTableAsStatementSegment"),
Ref("AlterTriggerStatementSegment"),
Ref("DropTypeStatementSegment"),
Ref("SetStatementSegment"),
],
)
Expand Down Expand Up @@ -2331,7 +2330,7 @@ class InsertStatementSegment(BaseSegment):
)


@postgres_dialect.segment()
@postgres_dialect.segment(replace=True)
jpy-git marked this conversation as resolved.
Show resolved Hide resolved
class DropTypeStatementSegment(BaseSegment):
"""Drop Type Statement.

Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/dialects/ansi/drop_type.sql
@@ -0,0 +1,7 @@
DROP TYPE typename;

DROP TYPE IF EXISTS typename;

DROP TYPE typename CASCADE;

DROP TYPE typename RESTRICT;
39 changes: 39 additions & 0 deletions test/fixtures/dialects/ansi/drop_type.yml
@@ -0,0 +1,39 @@
# 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: 72bf03f3af3cfac791a5bf91d0ca7751c6612592f5c2c8564d37dd77b5b28a1a
file:
- statement:
drop_type_statement:
- keyword: DROP
- keyword: TYPE
- object_reference:
identifier: typename
- statement_terminator: ;
- statement:
drop_type_statement:
- keyword: DROP
- keyword: TYPE
- keyword: IF
- keyword: EXISTS
- object_reference:
identifier: typename
- statement_terminator: ;
- statement:
drop_type_statement:
- keyword: DROP
- keyword: TYPE
- object_reference:
identifier: typename
- keyword: CASCADE
- statement_terminator: ;
- statement:
drop_type_statement:
- keyword: DROP
- keyword: TYPE
- object_reference:
identifier: typename
- keyword: RESTRICT
- statement_terminator: ;