builder: explain why boolean projections are rejected in sql.select() string columns
Los mantenedores suelen responder en 1 día
Evaluación
Este issue todavía no se ha evaluado.
Descripción
Summary
Passing a boolean projection as a string to sql.select(...) raises SQLBuilderError: Invalid column expression: '<text>' with no reason and no pointer to the supported form. The equivalent table-reference error already explains what to pass instead, so this one is harder to act on than it needs to be.
Reproduction
sqlspec==0.74.2
from sqlspec import sql
sql.select("u.id", "u.login_count > 0 AS has_logged_in").from_("users u")
sql.select("u.id", "(u.is_active AND u.is_verified) AS can_sign_in").from_("users u")
Both raise:
SQLBuilderError: Invalid column expression: 'u.login_count > 0 AS has_logged_in'
SQLBuilderError: Invalid column expression: '(u.is_active AND u.is_verified) AS can_sign_in'
Nearby forms build:
sql.select("u.id", "u.login_count + 1 AS next_login")
sql.select("u.id", "CASE WHEN u.login_count > 0 THEN TRUE ELSE FALSE END AS has_logged_in")
sql.select("u.id", sql.raw("u.login_count > 0 AS has_logged_in"))
Why it is confusing
A boolean projection is ordinary SQL on PostgreSQL, DuckDB, SQLite, and MySQL, and the arithmetic form of the same string is accepted. The message repeats the input without saying that a top-level comparison or AND/OR is what was rejected, so the natural reading is that the expression failed to parse. The usual reaction is to wrap the predicate in CASE WHEN ... THEN TRUE ELSE FALSE END, when sql.raw(...) would have kept the original expression.
Proposed change
When a string column is rejected for a top-level predicate or connector, say so and name the supported form, in the same style as the table-reference message. For example:
Invalid column expression 'u.login_count > 0 AS has_logged_in': column text cannot be a
top-level comparison or AND/OR expression. Pass an expression instead, such as
sql.raw('u.login_count > 0 AS has_logged_in'), or wrap it in CASE WHEN.
A short note in the query builder docs on boolean projections would cover the same gap.
Separately, it is worth deciding whether the restriction should apply to projections at all, since the same predicate is accepted inside CASE WHEN and through sql.raw. If it stays, the clearer message is enough.
- Lenguaje dominante
- Python
- Estrellas
- 110
- Forks
- 11
- Merge medio
- 19 h 9 min
- PR fusionados (30 d)
- 37
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 litestar-org/sqlspec
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
litestar-org/sqlspec#946 ·
Los mantenedores suelen responder en 1 día
-
bug
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
litestar-org/sqlspec#945 ·
Los mantenedores suelen responder en 1 día
-
builder: order_by("col", "asc") silently treats the direction as a columnPosiblemente ocupada @cofin la tomó hace 1 día. Abiertoenhancement
litestar-org/sqlspec#944 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
feat(litestar): support Litestar v3 compatibility and DI changesPosiblemente ocupada @cofin la tomó hace 14 días. Abiertoenhancement
litestar-org/sqlspec#926 · 1 asignado ·
Los mantenedores suelen responder en 1 día
-
Dificultad 5/5 Más de una semana Aptitud para principiantes 20/100
litestar-org/sqlspec#509 ·
Los mantenedores suelen responder en 1 día
Todos los issues de litestar-org/sqlspec
Issues similares
-
area:cli area:docs Platform vdr
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
NVIDIA-NeMo/Gym#7192 ·
Los mantenedores suelen responder en 2 días
-
Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mappingAbiertobug triage
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
aws-powertools/powertools-lambda-python#8948 ·
Los mantenedores suelen responder en 1 día
-
SofyaBotAbierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
ai-robots-txt/ai.robots.txt#324 ·
-
[Resource]: DashbarAbiertoresource-submission validation-passed
Dificultad 1/5 Menos de una hora Aptitud para principiantes 78/100
hesreallyhim/awesome-claude-code#3821 · 1 comentario ·
-
bug good first issue help wanted level 1 wocs
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
GianlucaBave/murmury#169 ·
Los mantenedores suelen responder en 1 día