Conversation
This was referenced Sep 16, 2026
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.
What
castStyle"cast""cast","operator"castkeeps today'sCAST(expr AS type).operatorprints the PostgreSQL-specificexpr::typeform, adding parentheses only where the tighter binding of::would otherwise change the meaning:Note the three groups: a column reference, a function call or an already-parenthesised sub-select needs nothing; an arithmetic or concatenation operand is parenthesised because
::binds tighter than+.A chained cast collapses to
t.a::text::bigintrather than nesting.Why
expr::typeis the form most PostgreSQL code is written in, and it is materially shorter in a long target list.The choice is a house-style question, so it is an option and the default does not move.
Implementation
nodes/type_cast.rsdecides on the spelling and on the parentheses from the argument node kind.The decision happens at emission time, which is why the emitter needs access to the configuration (see the prerequisite PR).
Wiring:
pgls_configuration(--cast-style),pgls_workspacesettings,docs/features/formatting.md,docs/schema.json.Tests
One fixture covering the nine argument shapes above, snapshotted at widths 80 and 100.
The two preparatory commits
The first two commits of this PR are shared, byte for byte, with the three other formatter-option PRs open alongside it:
commaStyle/logicalOperatorPlacementclauseBodyStyle/isolateSemicolonlayoutThe shared commits are:
test(pretty-print): allow per-fixture format configurationrefactor(pretty-print): thread the format config into the emitterThey are carried in each PR so every option remains independently reviewable and mergeable.
Whichever PR lands first, I will rebase the other three to remove the duplicate commits.
Merge them in whatever order suits you; nothing here depends on the others.