Skip to content

fix(e6): rewrite date + -N * INTERVAL as date - N * INTERVAL - #335

Merged
tkaunlaky-e6 merged 1 commit into
mainfrom
fix/e6-date-plus-n-interval
Nov 5, 2026
Merged

tkaunlaky-e6 merged 1 commit into
mainfrom
fix/e6-date-plus-n-interval

Conversation

@tkaunlaky-e6

Copy link
Copy Markdown

Problem

Samsung Tableau queries failed with PARSING_FAILED (36 failures from 3 distinct queries on 3 Nov):

Cannot apply 'DATE_ADD' to arguments of type 'DATE_ADD(<VARCHAR(3)>, <INTERVAL DAY>, <DATE>)'

Tableau sends CURRENT_DATE + -2 * INTERVAL '1 DAY'. The Postgres date + x rewrite in add_sql turned it into DATE_ADD('DAY', -2 * INTERVAL '1 DAY', CURRENT_DATE), passing an interval where the engine expects a number.

Fix

When the right side of date + ... is N * INTERVAL:

  • date + -N * INTERVAL -> date - N * INTERVAL
  • date + N * INTERVAL -> unchanged

Testing

  • New cases in test_postgres_date_addition_to_date_add (tests/dialects/test_e6.py)
  • make style and make test pass
  • Local engine: the old output reproduces the exact prod error; CURRENT_DATE - 2 * INTERVAL '1 DAY' returns today minus 2 days, CURRENT_DATE + 2 * INTERVAL '1 DAY' returns today plus 2 days
  • All 3 failing queries now convert without DATE_ADD in both Samsung and MULTIDIALECT modes

Postgres date + -N * INTERVAL was turned into DATE_ADD('DAY', -N * INTERVAL, date),
which the engine rejects (Cannot apply DATE_ADD to <VARCHAR>, <INTERVAL DAY>, <DATE>).
Emit date - N * INTERVAL instead and keep date + N * INTERVAL unchanged.
@tkaunlaky-e6
tkaunlaky-e6 merged commit 94aae68 into main Nov 5, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants