SQLite: day intervals on an expression of unknown type drop the time

Abierto
#9,303 0 comentarios 0 reacciones 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
65/100
Tipo de issue
Error
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
python, sql, sqlite
Área
databases

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
Python
Estrellas
9.8k
Forks
1.4k
Merge medio
10 h 52 min
PR fusionados (30 d)
303

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de tobymao/sqlglot

Todos los issues de tobymao/sqlglot

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.