You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(deparser): choose TypeCast syntax from the parse tree - #398
TypeCast deparsing now picks the cast form (expr::type vs CAST(expr AS type), and whether the argument needs parentheses) from the argument's AST node type instead of inspecting the deparsed string, and detects a qualified pg_catalog.bpchar from the TypeName.names nodes. The existing built-in type spelling policy is unchanged.
Tests: packages/deparser/__tests__/misc/typecast.test.ts adds 17 PG 18 cases asserting both emitted SQL and AST round-trip.
Its larger test file and long JSDoc, replaced by focused cases.
Its unary-minus expectations, which were wrong for PG 18: -1::integer parses as negation of a cast, (-1)::integer as a cast of a negative constant; the new tests assert the actual parse.
No version changes. #235 will be closed pointing here once this merges.
Improved SQL output for type casts, including negative numeric values, expressions, and schema-qualified types. Casts involving pg_catalog.bpchar and function calls now use appropriate SQL syntax.
Refines the deparser's TypeCast handling: a new isNegativeConstant helper detects signed A_Const values so bare :: syntax is not emitted where a leading minus would bind outside the cast, and the bpchar special case is narrowed to qualified pg_catalog.bpchar, falling back to CAST(...) otherwise. New tests cover casts of strings, negative integers/numerics, function calls, and bpchar variants.
Files
Change
packages/deparser/src/deparser.ts
Adds isNegativeConstant and simplifies TypeCast to choose :: vs CAST syntax based on argument shape and pg_catalog qualification.
packages/deparser/__tests__/misc/typecast.test.ts
New round-trip test suite covering 17 cast forms including negative constants and bpchar typmod/qualified variants.
No actionable comments were generated in the recent review.
Walkthrough
The deparser now detects negative constants and selects cast syntax based on the type and expression shape. Parameterized tests check deparsed output for text and numeric casts, expressions, pg_catalog.bpchar, and schema-qualified types.
TypeCast retains CAST(...) for qualified pg_catalog.bpchar casts and negative constants. Catalog-type casts of function calls use parenthesized postfix syntax. Columns and nonnegative constants use postfix casts directly. Parameterized tests check deparsed output across cast cases.
This change makes the deparser choose cast syntax from the parse tree instead of from rendered text. It adds tests for negative constants, bpchar and schema-qualified types. No concrete merge-blocking risk was found.
Security architecture risk: Minimal · up to 8fc80
The deparser now uses the shape of the parsed expression to choose cast syntax. This changes formatting without adding an input path, granting privileges, or executing SQL.
Pre-merge checks: 4
Check name
Status
Explanation
Description Check
Check skipped - CodeRabbit’s high-level summary is enabled.
Title check
The title names the main change: TypeCast deparsing now picks its syntax (postfix :: versus CAST(... AS ...)) from the parse tree. The summary and objectives confirm this is the core change. The t…
Linked Issues check
Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check
Check skipped because no linked issues were found for this pull request.
Full details: Title check
Explanation
The title names the main change: TypeCast deparsing now picks its syntax (postfix :: versus CAST(... AS ...)) from the parse tree. The summary and objectives confirm this is the core change. The title uses the conventional prefix and stays specific, so it is related to the changeset. The title is a single sentence of 57 characters and 8 words, which is concise.
Finishing Touches
Generate unit tests (beta)
Commit to this branch
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Reviewing files that changed from the base of the PR and between 890b03b and 8fc8028.
Files selected for processing: 2
packages/deparser/__tests__/misc/typecast.test.ts
packages/deparser/src/deparser.ts
Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 3 remain after this review.
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
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.
Summary
Fresh, minimal redo of #235 on current
main.TypeCastdeparsing now picks the cast form (expr::typevsCAST(expr AS type), and whether the argument needs parentheses) from the argument's AST node type instead of inspecting the deparsed string, and detects a qualifiedpg_catalog.bpcharfrom theTypeName.namesnodes. The existing built-in type spelling policy is unchanged.Tests:
packages/deparser/__tests__/misc/typecast.test.tsadds 17 PG 18 cases asserting both emitted SQL and AST round-trip.Left out from #235:
-1::integerparses as negation of a cast,(-1)::integeras a cast of a negative constant; the new tests assert the actual parse.No version changes. #235 will be closed pointing here once this merges.
Implemented in session Redo parse-tree-based TypeCast deparsing
Review with Devin · Open in Devin Desktop
Summary by CodeRabbit
pg_catalog.bpcharand function calls now use appropriate SQL syntax.