builder: explain why boolean projections are rejected in sql.select() string columns
メンテナーはふだん 1 日以内に返信
評価
この issue はまだ評価されていません。
説明
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.
- 主要言語
- Python
- スター
- 110
- フォーク
- 11
- 平均マージ
- 19時間 9分
- マージ済み PR(30日)
- 37
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
litestar-org/sqlspec のほかの issue
-
bug
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
litestar-org/sqlspec#946 ·
メンテナーはふだん 1 日以内に返信
-
bug
難易度 3/5 1〜2日 初心者へのやさしさ 68/100
litestar-org/sqlspec#945 ·
メンテナーはふだん 1 日以内に返信
-
builder: order_by("col", "asc") silently treats the direction as a column対応中かも @cofin が 1 日前に担当しました。 オープンenhancement
litestar-org/sqlspec#944 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
feat(litestar): support Litestar v3 compatibility and DI changes対応中かも @cofin が 14 日前に担当しました。 オープンenhancement
litestar-org/sqlspec#926 · 担当者 1 名 ·
メンテナーはふだん 1 日以内に返信
-
難易度 5/5 1週間以上 初心者へのやさしさ 20/100
litestar-org/sqlspec#509 ·
メンテナーはふだん 1 日以内に返信
litestar-org/sqlspec の issue をすべて見る
似ている issue
-
area:cli area:docs Platform vdr
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
NVIDIA-NeMo/Gym#7192 ·
メンテナーはふだん 2 日以内に返信
-
Bug: CaseInsensitiveDict (event.headers) returns True for both == and != against the same mappingオープンbug triage
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
aws-powertools/powertools-lambda-python#8948 ·
メンテナーはふだん 1 日以内に返信
-
SofyaBotオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 66/100
ai-robots-txt/ai.robots.txt#324 ·
-
[Resource]: Dashbarオープンresource-submission validation-passed
難易度 1/5 1時間未満 初心者へのやさしさ 78/100
hesreallyhim/awesome-claude-code#3821 · コメント 1 件 ·
-
bug good first issue help wanted level 1 wocs
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
GianlucaBave/murmury#169 ·
メンテナーはふだん 1 日以内に返信