Skip to content

feat: diagnose untyped placeholders and suggest a cast - #75

Merged
omer-cengel merged 2 commits into
masterfrom
feature/untyped-placeholder-diagnostic
Oct 11, 2026
Merged

omer-cengel merged 2 commits into
masterfrom
feature/untyped-placeholder-diagnostic

Conversation

@omer-cengel

Copy link
Copy Markdown
Member

Summary

A placeholder that no clause types and no cast states the type of was rejected with a generic placeholder-accounting message that did not say which placeholder failed or how to fix it. It is now rejected as Cannot infer the type of <placeholder> in <where>; state it with a cast, such as <placeholder>::text, naming the placeholder as the query spells it and where the query writes it.

Changes

  • The SQL parser reports where each placeholder occurrence stands: the smallest expression written around it, on one line with any whitespace or comment between tokens written as one space, or, when it stands alone in its clause, that clause's keyword in upper case (SELECT, DISTINCT ON, ON, WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, OFFSET, FETCH, VALUES, SET, or RETURNING).
  • Query analysis reports the first untyped placeholder in textual order with the new diagnostic, in both $1 and :name forms.
  • A bare placeholder projection, such as SELECT $1 AS x, gets the same diagnostic instead of the unsupported-expression rejection.
  • Analyzer, parser, and compiler tests cover the diagnostic, including the whole one-line located message for an expression written across lines.
  • The query documentation describes the diagnostic and how its location is named.

Scope and non-goals

  • No new type inference: the suggested cast is always ::text.
  • Rejections raised by a clause's own rules, such as a LIKE pattern shape, an = ANY column type, or an unsupported cast type in a clause, still come first.
  • Accepted queries keep their parameters, names, types, and binding order.
  • Bare RETURNING placeholders and computed projections keep their current rejections, and the internal placeholder accounting check is unchanged.

A placeholder that no clause types and no cast states the type of is now
rejected as "Cannot infer the type of <placeholder> in <where>; state it
with a cast, such as <placeholder>::text", naming the first such
placeholder in textual order as the query spells it. A bare placeholder
projection gets the same diagnostic. Clause rejections still come first,
and the placeholder accounting check remains as an internal guard.
@omer-cengel
omer-cengel merged commit 6882912 into master Oct 11, 2026
7 checks passed
@omer-cengel
omer-cengel deleted the feature/untyped-placeholder-diagnostic branch October 11, 2026 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant