Skip to content

Commit

Permalink
Fix: default cast at create table returns unparsable section (#4192)
Browse files Browse the repository at this point in the history
Co-authored-by: Barry Hart <barrywhart@yahoo.com>
  • Loading branch information
NelsonTorres and barrywhart committed Dec 22, 2022
1 parent 1b0dc82 commit 056ce08
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
5 changes: 4 additions & 1 deletion src/sqlfluff/dialects/dialect_ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2651,7 +2651,10 @@ class ColumnConstraintSegment(BaseSegment):
Sequence( # DEFAULT <value>
"DEFAULT",
OneOf(
Ref("LiteralGrammar"),
OneOf(
Ref("ShorthandCastSegment"),
Ref("LiteralGrammar"),
),
Ref("FunctionSegment"),
Ref("BareFunctionSegment"),
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,6 @@ create table table1 (
c6 INT REFERENCES table2 (c6_other) ON DELETE NO ACTION,
c6 INT REFERENCES table2 (c6_other) ON UPDATE SET NULL,
c6 INT REFERENCES table2 (c6_other) ON DELETE RESTRICT ON UPDATE CASCADE,
c7 INT NOT NULL DEFAULT 1 UNIQUE REFERENCES table3 (c7_other)
c7 INT NOT NULL DEFAULT 1 UNIQUE REFERENCES table3 (c7_other),
c8 INT NOT NULL DEFAULT 1::INT
)
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# 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: 20afc12c71a054d29ed4c94899e27b32231d963355d407c2ede40fde7a5ed4ad
_hash: d7769d9eb54abd09aa301054592b03b6258fb68d97f01f894f52b65d67cb820e
file:
statement:
create_table_statement:
Expand Down Expand Up @@ -194,4 +194,19 @@ file:
column_reference:
naked_identifier: c7_other
end_bracket: )
- comma: ','
- column_definition:
- naked_identifier: c8
- data_type:
data_type_identifier: INT
- column_constraint_segment:
- keyword: NOT
- keyword: 'NULL'
- column_constraint_segment:
keyword: DEFAULT
cast_expression:
numeric_literal: '1'
casting_operator: '::'
data_type:
data_type_identifier: INT
- end_bracket: )

0 comments on commit 056ce08

Please sign in to comment.