pub fn pretty_expr(e: &Expr) -> StringExpand description
v7.39 (round 311, V32) — PG’s PRETTY deparse of an expression, the
form pg_get_constraintdef(oid, true) and friends return.
The default fmt::Display parenthesises every operator node, which
is what PG’s non-pretty deparse does and what makes the text
round-trip. Pretty drops the pairs the grammar can put back, and the
rule is NOT plain precedence minimisation — measured against PG 18.4
across 37 shapes:
- the boolean layer follows precedence (NOT > AND > OR): an OR
under an AND keeps its parens, an AND under an OR does not, and a
comparison under any of them does not (
NOT a > 1); - an associative chain flattens completely, even where the source
nested it to the right (
a AND (b AND c)prints as one chain); - but an operand of a comparison or arithmetic operator keeps its
parens whenever it is itself an operator expression — so
(a + b) > 10and(- a) + b, even though precedence alone would not require either. A cast, function call, column or literal in that position does not (a::text = t,length(code) > 2); a cast counts as compound exactly when the thing it casts is (((a + b)::text) = t).
Anything outside that layer defers to Display, which is never
wrong — only more parenthesised than PG would print.