fix(parse): read a :: cast as a cast, not as a column name - #340
Merged
Conversation
StrictRow<DB, 'select id::text as id_text from users'>
// was QueryTypeError<'unknown column: id::text'>
`:` is not in OperatorChar and nothing stripped a `::type` suffix, so the
whole token fell through to BareColumnType as a literal name. Loose mode was
harmless about it, but in strict mode one cast poisoned the whole row, and
`::` is clearly in-dialect for the library: `$1::int` in params is supported
and tested.
The operand is resolved as an expression of its own, so a typo inside the
cast is still caught (`naem::text` still reports `unknown column: naem`, a
bad qualifier still reports `unknown alias`). The column itself types
`unknown`: the cast is what decides the type, and this parser does not model
SQL type names.
Fixes #277
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
tiagolauer
force-pushed
the
fix/277-cast-in-select-list
branch
from
August 2, 2026 13:04
6506b4f to
c1d5a70
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #277.
The bug
Loose mode is harmless (
{ 'id::text': unknown }[]), but one cast column poisons the whole strict row. The::syntax is clearly in-dialect for the library:$1::intin params is supported and tested.The fix
':'is not inOperatorCharand nothing stripped a::typesuffix, soid::textfell through toBareColumnTypeas a literal column name.A cast expression now resolves its operand and reports
unknownfor the column. That keeps the check where it is useful — a typo inside the cast still errors — without claiming a type the parser cannot know: the cast is what decides it, and SQL type names are not modelled here.Verification
tests/cast-columns.test-d.ts, nine cases. Five red on master:naem::textstill reportsunknown column: naem, andp.id::textwith nopsource still reportsunknown alias: pControls: loose mode is unchanged, a plain column is unchanged, and
count(*)::intresolves through the same path.tsc --noEmitclean, budget 194,259 (+1,773).