Many times, I'm able to write a PL/PGSQL UDF in two ways:
- As a big query usually using WITH clauses and UNION (i.e. more declarative but also more complex to write/read)
- As multiple smaller queries (i.e. more procedural but also easier to write/read)
I'm aware that PG query planner will plan each smaller query in UDF individually, and I'm afraid that might have an impact on overall performance. What do you guys prefer?