SQLite: CAST(x AS JSON) is generated verbatim, which SQLite evaluates as a numeric cast
Los mantenedores suelen responder en 1 día
@Gowthamsuryagolla ya está trabajando en esto.
Desde el 15/11/2026.
- #9116 de @Gowthamsuryagolla — abierto
Evaluación
- Dificultad
- 3/5
- Tiempo estimado
- Medio día
- Aptitud para principiantes
- 32/100
Línea de trabajo
The SQLite generator lives in sqlglot/dialects/sqlite.py; start by finding where exp.Cast is rendered there and compare with the temporal-cast handling added in #8793. Reproduce with the snippet in the issue, then check the existing expectations in tests/dialects/test_sqlite.py. Done means CAST(x AS JSON)/JSONB emits JSON(x) while non-JSON casts are untouched, and the round-trip test plus the full dialect test file pass.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Fully reproducible code snippet
SQLite has no JSON type, so CAST(x AS JSON) gets NUMERIC affinity: CAST('{"a": 1}' AS JSON) evaluates to the integer 0. The sqlite generator emits JSON casts unchanged, so a very common Postgres pattern silently returns NULL after transpiling:
import sqlite3, sqlglot
sql = """SELECT '{"a": 1}'::json ->> 'a'"""
out = sqlglot.transpile(sql, read="postgres", write="sqlite")[0]
print(out)
# SELECT CAST('{"a": 1}' AS JSON) ->> '$.a'
print(sqlite3.connect(":memory:").execute(out).fetchall())
# [(None,)] Postgres returns '1'
Same with read="duckdb" / read="mysql": SELECT CAST('{"a": 1}' AS JSON) stays as is, and SQLite returns 0 instead of the JSON text.
Expected: JSON(x) (or just x) for JSON/JSONB casts, like the temporal casts that became DATE(x) / DATETIME(x) / TIME(x) in #8793. JSON(x) keeps the cast's validation (it errors on malformed input), and JSON('{"a": 1}') ->> '$.a' returns 1. BigQuery's JSON '...' literal already becomes a plain string here, so the target output works fine with SQLite's JSON functions.
Official Documentation
- Type affinity rules (a declared type with none of INT/CHAR/CLOB/TEXT/BLOB/REAL/FLOA/DOUB is NUMERIC): https://www.sqlite.org/datatype3.html#determination_of_column_affinity
- CAST to NUMERIC affinity: https://www.sqlite.org/lang_expr.html#castexpr
json(X): https://www.sqlite.org/json1.html#jmini
Tested on main at b294f7f, SQLite 3.54.1.
- Lenguaje dominante
- Python
- Estrellas
- 9.8k
- Forks
- 1.4k
- Merge medio
- 13 h 19 min
- PR fusionados (30 d)
- 243
Preparar el entorno
- Sin Dockerfile ni archivo de Docker Compose
- Sin plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de tobymao/sqlglot
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
Los mantenedores suelen responder en 1 día
-
Dificultad 4/5 3-5 días Aptitud para principiantes 30/100
Los mantenedores suelen responder en 1 día
-
Optimizer drops parentheses for `NOT (<date> = DATE_TRUNC(...))`, changing query resultsPosiblemente ocupada @parthdembla007 la tomó hoy. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 28/100
Los mantenedores suelen responder en 1 día
-
BigQuery: region-qualified INFORMATION_SCHEMA reference is rewritten across transpile passes, gaining an invented aliasPosiblemente ocupada @ansh-rohilla la tomó hoy. Abierto
Dificultad 4/5 3-5 días Aptitud para principiantes 28/100
Los mantenedores suelen responder en 1 día
-
DATE_ADD/DATE_SUB with a single argument raises AttributeError (BigQuery, MySQL, Doris, StarRocks)Posiblemente ocupada @akchhayasharma la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 42/100
Los mantenedores suelen responder en 1 día
Todos los issues de tobymao/sqlglot
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
alltheplaces/alltheplaces#20570 · 2 comentarios ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
area:ci bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 85/100
catincloud-labs/dagster-dex#206 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
number_to_words raises ValueError with threshold= for ordinals ("12th") and comma-grouped strings ("1,000")Posiblemente ocupada @hemtilva la tomó hoy. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
Los mantenedores suelen responder en 1 día
-
providers security
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
agentbreeder/agentbreeder#1031 ·
Los mantenedores suelen responder en 1 día