Skip to content

BigQuery→DuckDB: DATE_ADD with non-literal INTERVAL expression emits invalid SQL (missing parentheses, nested DATE_DIFF not transpiled) #477

Description

@nikchha

DATE_ADD(date, INTERVAL <expr> <part>) where <expr> is not a literal produces invalid DuckDB SQL: the interval expression is emitted without parentheses, and a nested function inside it is not transpiled.

Version: @polyglot-sql/sdk 0.12.1, DuckDB 1.5.5

Repro 1: column reference

transpile(
  "SELECT DATE_ADD(DATE '2026-01-01', INTERVAL n MONTH) AS d FROM (SELECT 2 AS n)",
  Dialect.BigQuery,
  Dialect.DuckDB,
).sql[0];

Actual:

SELECT CAST('2026-01-01' AS DATE) + INTERVAL n MONTH AS d FROM (SELECT 2 AS n)

DuckDB: Parser Error: syntax error at or near "MONTH"

Expected: ... + INTERVAL (n) MONTH ..., which DuckDB accepts and returns 2026-03-01.

Repro 2: nested DATE_DIFF

transpile(
  "SELECT DATE_ADD(DATE '2026-01-01', INTERVAL DATE_DIFF(DATE '2026-03-15', DATE '2026-01-01', MONTH) MONTH) AS d",
  Dialect.BigQuery,
  Dialect.DuckDB,
).sql[0];

Actual:

SELECT CAST('2026-01-01' AS DATE) + INTERVAL DATE_DIFF(CAST('2026-03-15' AS DATE), CAST('2026-01-01' AS DATE), MONTH) MONTH AS d

DuckDB: Parser Error: syntax error at or near "("

Besides the missing parentheses, the inner DATE_DIFF keeps BigQuery argument order and syntax. At top level the same call is transpiled correctly to DATE_DIFF('MONTH', CAST('2026-01-01' AS DATE), CAST('2026-03-15' AS DATE)), so the interval's inner expression seems to skip the dialect transforms.

Expected:

SELECT CAST('2026-01-01' AS DATE) + INTERVAL (DATE_DIFF('MONTH', CAST('2026-01-01' AS DATE), CAST('2026-03-15' AS DATE))) MONTH AS d

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions