@Charlieface adding to the encore discussion, Postgres inlines a CTE only if it is referenced only once, it has no volatile functions and is non-recursive. Everything else is materialised / evaluated once (assuming no overrides with [NOT] MATERIALIZED. That is for versions 12+.
@AndrásVáczi not sure about tonight, I'm working until late. If you are still in Athens tomorrow, send me a message and we could meet. ypercube @ gmail.com