Skip to content

Commit 422a92b

Browse files
authored
MySQL: Fix parsing 'ALTER TABLE ts ADD COLUMN modified_at TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP;' (#5766) (#5767)
1 parent cda058e commit 422a92b

3 files changed

Lines changed: 16 additions & 5 deletions

File tree

src/sqlfluff/dialects/dialect_mysql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ class ColumnDefinitionSegment(BaseSegment):
338338
),
339339
Ref("NumericLiteralSegment"),
340340
Ref("QuotedLiteralSegment"),
341+
"NULL",
341342
),
342343
optional=True,
343344
),

test/fixtures/dialects/mysql/create_table_datetime.sql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ CREATE TABLE `foo` (
2020
ts12 TIMESTAMP NULL DEFAULT '0000-00-00 00:00:00',
2121
ts13 TIMESTAMP NULL DEFAULT NOW ON UPDATE NOW,
2222
ts14 TIMESTAMP NULL DEFAULT NOW() ON UPDATE NOW(),
23-
ts15 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
23+
ts15 TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
24+
ts16 TIMESTAMP NULL DEFAULT NULL ON UPDATE CURRENT_TIMESTAMP
2425
)

test/fixtures/dialects/mysql/create_table_datetime.yml

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# computed by SQLFluff when running the tests. Please run
44
# `python test/generate_parse_fixture_yml.py` to generate them after adding or
55
# altering SQL files.
6-
_hash: e9c33e67e5d27f30efd11d52a52f8df18d2b949a6a4585b07a9053b6d4e5f1a8
6+
_hash: 7d380062698a45e2def8a6ea2766b072296d0f462727a05fddfceddc50c2e735
77
file:
88
statement:
99
create_table_statement:
@@ -137,9 +137,8 @@ file:
137137
- naked_identifier: ts8
138138
- keyword: TIMESTAMP
139139
- keyword: 'NULL'
140-
- column_constraint_segment:
141-
keyword: DEFAULT
142-
null_literal: 'NULL'
140+
- keyword: DEFAULT
141+
- keyword: 'NULL'
143142
- comma: ','
144143
- column_definition:
145144
- naked_identifier: ts9
@@ -208,4 +207,14 @@ file:
208207
- keyword: 'ON'
209208
- keyword: UPDATE
210209
- keyword: CURRENT_TIMESTAMP
210+
- comma: ','
211+
- column_definition:
212+
- naked_identifier: ts16
213+
- keyword: TIMESTAMP
214+
- keyword: 'NULL'
215+
- keyword: DEFAULT
216+
- keyword: 'NULL'
217+
- keyword: 'ON'
218+
- keyword: UPDATE
219+
- keyword: CURRENT_TIMESTAMP
211220
- end_bracket: )

0 commit comments

Comments
 (0)