On Mon, Feb 12, 2018 at 6:48 AM, PegoraroF10 <marcos@f10.com.br> wrote:
Another approach to solve my problem would be a function that receives a dynamic SQL, runs it and returns a XML or JSON and on client side I convert that XML back to a recordset. Is that possible ?
Yes, you can pass "text" SQL into a pl/pgsql function and "EXECUTE" it. That text must be plain SQL though, not pl/pgsql.
Converting pl/pgsql into plain SQL and executing it as a CTE seems like an over-solution. What should be reasonably possible to rewrite the "execute block" as a "create function" then modify your clients to do send "select * from function();" instead of "execute block ..."
If I was you I'd even be curious enough to see if maybe there is an external third-party extension "pl/firebase" language out there which would let you comfortably copy-paste the block text into the function body with minimal or no editing.
David J.
p.s. reading PostGres is hard on our (mine at least) eyes. Its either Postgres, or PostgreSQL - neither with a capital G.