lelit/pglast

pgpp remove important parentheses

Closed this issue · 3 comments

pgpp -v
pgpp 5.5, with PostgreSQL 15.1 parser

The example is reduced from a much larger query. I used version 3 before where it works, but the output had much more parentheses.

I wish we had both, an option with as much brackets as possible to see the operator priority (like in V3) and one reduced as much as possible (kind of V5)

# ok
pgpp -S 'select * from fmt a, fmt b where a.id <> b.id and (not a.f or b.f)'
SELECT *
FROM fmt AS a, fmt AS b
WHERE a.id <> b.id
  AND (NOT a.f
    OR b.f)
# ok
pgpp -m 30 -S 'select * from fmt a, fmt b where a.id <> b.id and (not a.f or b.f)'
SELECT *
FROM fmt AS a, fmt AS b
WHERE a.id <> b.id
  AND (NOT a.f OR b.f)
# failed - the parentheses make a difference here
pgpp -m 120 -S 'select * from fmt a, fmt b where a.id <> b.id and (not a.f or b.f)'
SELECT *
FROM fmt AS a, fmt AS b
WHERE a.id <> b.id AND NOT a.f OR b.f

Ouch, this really surprise me, the --compact-lists-margin should definitively not affect the resulting AST!

Thanks for the report, I will investigate as soon as I can, but I'm afraid it will take a while since I'm moving to a new home and have no connectivity yet.

WRT the new "don't elide pointless parens", I will consider that, it should not be very difficult...

The fix was rather simple 😉, while that proposal for a new option to emit redundant parenthesis is not so trivial, sorry.

This is fixed in v5.6 that I'm about to release.