Hi.
I'm playing with the tsql grammar forking it for Sybase.
I have a real world case supported by SQLServer and ASE not addressed in the grammar's test cases which is causing a parse error.
The rule null_notnull seems to be not handled properly due to the invalid syntax "GETDATE() + GETDATE()"
. Not being quite sure on debugging grammars in antlr4, I'm not sure how rule null_notnull is being handled, the error refers to a missing ")"
The DEFAULT syntax should be any expression that results in a single value.
I need some appreciated help supporting DEFAULT's syntax.
Unsuccessful experiments resulting in the same error, changing constant_expression rule to:
| function_call (PLUS function_call)* | expression | expression*
The column definition in the db:[C4] varchar(14) DEFAULT CONVERT(char(8), GETDATE(), 112) + substring(CONVERT(char(8), GETDATE(), 8), 1, 2) + substring(CONVERT(char(8), GETDATE(), 8), 4, 2) + substring(CONVERT(char(8), GETDATE(), 8), 7, 2)/* Current Datetime*/ NOT NULL,
The simplified test case is:
CREATE TABLE T1 (
[C8] varchar(14) DEFAULT GETDATE() + GETDATE() NOT NULL,
);
The error is: line 13:49 extraneous input 'NOT' expecting
The offending parse tree:( ) [line 13, offset 298:304]) NOT [line 13, offset 278:284]) [line 13, offset 278:284]) [line 13, offset 261:264]) <missing ')'> [line 12, offset 239:244]) [line 12, offset 239:244]) [line 12, offset 239:244])
The Rules:
column_definition
: id (data_type | AS expression) (COLLATE id)? null_notnull?
((CONSTRAINT constraint=id)? null_or_default null_or_default?
| IDENTITY (L_PAREN seed=DECIM_VAL ',' increment=DECIM_VAL R_PAREN)? (NOT FOR REPLICATION)?)?
ROWGUIDCOL?
column_constraint*
;
null_or_default
:(null_notnull | DEFAULT constant_expression (WITH VALUES)?)
;
null_notnull
: NOT? NULL
;
constant_expression
: NULL
| constant
// system functions: https://msdn.microsoft.com/en-us/library/ms187786.aspx
| function_call
| LOCAL_ID // TODO: remove.
| L_PAREN constant_expression R_PAREN
;