Repository navigation
fix(pretty-print): keep negative constants and FROM casts valid with castStyle=operator - #848
Merged
psteinroe merged 1 commit intoOct 11, 2026
Conversation
…castStyle=operator
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.
With
castStyle: "operator", the formatter changed the meaning of two kinds of casts.A negative numeric constant lost its parentheses.
CAST(-2147483648 AS int)became-2147483648::int, which casts2147483648first and fails withinteger out of range.CAST(-12345 AS money)became-12345::money, a negation of a cast instead of a cast of a negative constant.A cast used as a table function in
FROMwas written as::.FROM CAST(1 + 2 AS int) AS abecameFROM (1 + 2)::int AS a, which is a syntax error. The safety check rejected both outputs, so the statements were left unformatted.This change parenthesizes a negative numeric constant before
::, and always emitsCAST(...)for a cast that is aFROMitem, including insideROWS FROM. It adds thecast_operator_style_negative_constantandcast_operator_style_from_clausefixtures with snapshots generated from a real test run.Running the Postgres regression statements through the formatter with
castStyle: "operator"found 63 failing statements across the Postgres 15, 16, and 17 suites, all from these two causes. With this change, none fail.Test: