sqlglot icon indicating copy to clipboard operation
sqlglot copied to clipboard

DATE_ADD/DATE_SUB with a single argument raises AttributeError (BigQuery, MySQL, Doris, StarRocks)

Open Sun-Wukhan opened this issue 2 weeks ago • 0 comments

Fully reproducible code snippet

import sqlglot

sqlglot.parse_one("SELECT DATE_ADD(x)", read="bigquery")
# AttributeError: 'NoneType' object has no attribute 'error_messages'

The same applies to DATE_SUB, DATETIME_ADD/SUB, TIME_ADD/SUB and TIMESTAMP_ADD/SUB in BigQuery, DATE_ADD/DATE_SUB in MySQL, and the Doris/StarRocks registrations of the same builder.

Expected

A ParseError. The same input in DuckDB raises a clean ParseError; BigQuery DATE_DIFF(x) raises ParseError; and BigQuery DATE_SUB(x, 1) raises "ParseError: INTERVAL expression expected but got '1'".

Actual

The dialect builder build_date_delta_with_interval returns None when len(args) < 2, and Parser.validate_expression then dereferences None.error_messages (in parser.py), producing the AttributeError.

Checked against main at commit b294f7f.

Official Documentation

BigQuery DATE_ADD requires a date expression and an INTERVAL: https://cloud.google.com/bigquery/docs/reference/standard-sql/date_functions#date_add MySQL DATE_ADD: https://dev.mysql.com/doc/refman/8.0/en/date-and-time-functions.html

Found by property-based testing (a no-crash property over mutated inputs drawn from sqlglot's own test corpus).

Sun-Wukhan avatar Nov 14 '26 21:11 Sun-Wukhan