Skip to content

Commit bb9f7e8

Browse files
committed
TSQL: Fix bare functions in default constraints
1 parent cda058e commit bb9f7e8

3 files changed

Lines changed: 17 additions & 1 deletion

File tree

src/sqlfluff/dialects/dialect_tsql.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2435,6 +2435,7 @@ class ColumnConstraintSegment(BaseSegment):
24352435
OptionallyBracketed(
24362436
OneOf(
24372437
OptionallyBracketed(Ref("LiteralGrammar")), # ((-1))
2438+
Ref("BareFunctionSegment"),
24382439
Ref("FunctionSegment"),
24392440
Ref("NextValueSequenceSegment"),
24402441
),

test/fixtures/dialects/tsql/create_table_constraints.sql

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ CREATE TABLE [dbo].[example](
33
[Column B] [int] IDENTITY(1, 1) NOT NULL,
44
[ColumnC] varchar(100) DEFAULT 'mydefault',
55
[ColumnDecimal] DATE DEFAULT GETDATE(),
6+
[ColumnUser] char(30) DEFAULT CURRENT_USER,
67
[col1] int default ((-1)) not null,
78
[col1] int default (-1) not null,
89
[col1] int default -1 not null,

test/fixtures/dialects/tsql/create_table_constraints.yml

Lines changed: 15 additions & 1 deletion
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: 64ba76dd590a430fec124b6c9c189c2d5c2961c3406a0b510accba6391210307
6+
_hash: c75e9d7b8dd1b4bafaa40bb49ba25f4732ecef4cc1c4adc176a43dc05b9dabbe
77
file:
88
- batch:
99
statement:
@@ -68,6 +68,20 @@ file:
6868
start_bracket: (
6969
end_bracket: )
7070
- comma: ','
71+
- column_definition:
72+
quoted_identifier: '[ColumnUser]'
73+
data_type:
74+
data_type_identifier: char
75+
bracketed_arguments:
76+
bracketed:
77+
start_bracket: (
78+
expression:
79+
numeric_literal: '30'
80+
end_bracket: )
81+
column_constraint_segment:
82+
keyword: DEFAULT
83+
bare_function: CURRENT_USER
84+
- comma: ','
7185
- column_definition:
7286
- quoted_identifier: '[col1]'
7387
- data_type:

0 commit comments

Comments
 (0)