#8589·sqlfluff

Parser does not validate data type argument arity (e.g. `DECIMAL(10, 2, 3)` is accepted)

Author: taslaterCreated Sep 26, 2026Updated Sep 26, 2026
  • I searched the issues and found no similar issues.

What Happened

While checking Databricks SQL I found that CREATE TABLE t (a DECIMAL(10, 2, 3)) parses with no violations. DECIMAL/NUMERIC take at most a precision and an optional scale (0–2 arguments), so a third argument is invalid here.

Looking at the shared grammar, this isn't specific to DECIMAL: the ANSI DatatypeSegment attaches an unconstrained bracketed argument list to any primitive type name, so argument arity is never validated for any data type. VARCHAR(3, 4), CHAR(3, 4) and INT(1, 2, 3) are accepted as well.

Expected Behaviour

SQLFluff should report the input as unparsable (Found unparsable section), because the type accepts at most two bracketed arguments.

Observed Behaviour

No violations; sqlfluff parse exits 0 and builds a bracketed_arguments node containing three numeric literals:

$ echo 'CREATE TABLE t (a DECIMAL(10, 2, 3));' | sqlfluff parse - --dialect ansi
...
|                    data_type:
|                        primitive_type:
|                            keyword:                          'DECIMAL'
|                            bracketed_arguments:
|                                bracketed:
|                                    start_bracket:            '('
|                                    numeric_literal:          '10'
|                                    comma:                    ','
|                                    numeric_literal:          '2'
|                                    comma:                    ','
|                                    numeric_literal:          '3'
|                                    end_bracket:              ')'
...

Identical result (accepted, no violations) for ansi, databricks, sparksql, postgres and snowflake, on both the Python and Rust parsers.

How to reproduce

bash
$ echo 'CREATE TABLE t (a DECIMAL(10, 2, 3));' | sqlfluff parse - --dialect ansi >/dev/null; echo "exit: $?"
exit: 0

Other over-accepted examples (each independent):

sql
CREATE TABLE t (a NUMERIC(1, 2, 3));
CREATE TABLE t (a VARCHAR(3, 4));
CREATE TABLE t (a CHAR(3, 4));
CREATE TABLE t (a INT(1, 2, 3));

Valid controls DECIMAL(10, 2), DECIMAL(10) and VARCHAR(3) are also accepted, as expected.

Dialect

All dialects that inherit the ANSI data type grammar. Verified directly on ansi, databricks, sparksql, postgres and snowflake.

Version

  • main at c7401613e851a6913ec3de8e003247e6fe8e5387 (2026-09-26), Python and Rust parsers both
  • Released 4.3.0 reproduces as well

Configuration

None — defaults. Command used: sqlfluff parse - --dialect ansi.

Likely root cause

BracketedArguments in src/sqlfluff/dialects/dialect_ansi.py:1020 is a plain delimited literal list with no cardinality constraint:

python
class BracketedArguments(BaseSegment):
    type = "bracketed_arguments"
    match_grammar = Bracketed(
        # The brackets might be empty for some cases...
        Delimited(Ref("LiteralGrammar"), optional=True),
    )

and DatatypeSegment (dialect_ansi.py:1033) references it after any DatatypeIdentifierSegment:

python
Ref("DatatypeIdentifierSegment"),
allow_gaps=False,
...
Ref("BracketedArguments", optional=True),

Because the same unconstrained BracketedArguments is shared across data-type productions — and inherited by many dialects (postgres, oracle, athena, hive, teradata reference it; TSQL and Exasol subclass it) — there is nowhere for a per-type arity rule to live. A proper fix likely means a type-family argument production with its own cardinality constraint, rather than further relaxing the shared one. Happy to be guided on the preferred shape.

Are you willing to work on and submit a PR to address the issue?

  • Yes I am willing to submit a PR!

  • I agree to follow this project's Code of Conduct