SQLite: day intervals on an expression of unknown type drop the time
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 65/100
Research direction
Start by running the reproducer: sqlglot.transpile("SELECT ts + INTERVAL 1 DAY FROM t", read="duckdb", write="sqlite") and trace it into the SQLite dialect's interval generator, where day/week/month/year units choose DATE() while hour/minute/second use DATETIME(). Compare that path with the annotated-schema handling for DATE and TIMESTAMP columns. Add a regression case to the SQLite transpilation tests for unknown-type timestamp intervals; done means the output either keeps the time or reports the case as unsupported without changing known DATE/TIMESTAMP behavior.
Written by the indexing model from the issue text.
Description
For an interval added to an expression of unknown type, the SQLite generator picks DATE() for day, week, month and year units, which drops the time of a value that holds a timestamp:
import sqlglot
sqlglot.transpile("SELECT ts + INTERVAL 1 DAY FROM t", read="duckdb", write="sqlite")
# ["SELECT DATE(ts, '1 DAY') FROM t"]
With t.ts holding '2024-01-15 23:30:00', SQLite returns '2024-01-16', while DuckDB (with ts TIMESTAMP) returns 2024-01-16 23:30:00. Hour, minute and second units already use DATETIME(), which keeps the time.
Without type information the generator can't tell date text from timestamp text, so either choice is wrong for one of them. It may be safer to flag the unknown-type case as unsupported, unless the caller annotates types with a schema, in which case DATE and TIMESTAMP columns are already handled correctly.
I found this while running BenchBox benchmarks on SQLite. The issue was drafted with Claude.
- Dominant language
- Python
- Stars
- 9.8k
- Forks
- 1.4k
- Avg merge
- 10h 52m
- Merged PRs (30d)
- 303
Getting set up
- No Dockerfile or Docker Compose file
- No pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tobymao/sqlglot
-
Difficulty 1/5 Under an hour Newbie friendliness 85/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
Maintainers usually reply within 1 day
-
Difficulty 3/5 1-2 days Newbie friendliness 66/100
Maintainers usually reply within 1 day
Similar issues
-
Difficulty 1/5 Under an hour Newbie friendliness 86/100
py-econometrics/pyfixest#2072 ·
Maintainers usually reply within 1 day
-
~planning docs
Difficulty 2/5 1-3 hours Newbie friendliness 64/100
Kromatic-Innovation/athenaeum#3084 ·
Maintainers usually reply within 1 day
-
Bosch Room Thermostat II number entities offer -500 to 3000 °C setpoint limits and a -32768 to 32767 °C outdoor temperaturePossibly taken @zigpy-review-bot claimed this today. Openbot: code audit
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
zigpy/zha-device-handlers#5769 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 Half a day Newbie friendliness 80/100
R0Y00/Xbox2Windows#254 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
Kludex/python-multipart#375 ·
Maintainers usually reply within 1 day