I do want to query specific information from all tables in the DB:
select *
from [pg_catalog.]pg_tables
where schemaname = '<Schema>';
The only way I appear to do it (I accept any suggestions) without creating a temporary table, would be to develop a function executing a loop on the schema tables (Loop on Cursor with that query) and then for each table in the schema I would call a function executing dynamic pgsql to obtain the desired information from that table in the schema. This second function requires dynamic sql (I believe) as the table name on which I want to execute a query on, would vary and so, should be passed as an argument to the function.
The idea would be that this "called" function would be returning a record type and then the main (or "calling") function should return a table type, and this is where I get lost.
What I don´t know how to solve (And don´t know that can be solved at all) would be how to construct a function returning a table type (Or some data structure that could be listed when I call the function from sql editor) which internally calls a function returning a record (Same structure of the table returned by "calling" function). In all examples I see about function returning tables, the return is the execution of a select, but I don´t find any example of pgsql function returning table type that internally constructs the table structure. And I don´t know that is possible at all either.
- Of course, the same example could be implemented in one single function, but I would still find the same problem about a function returning table type executing different queries that return record type. Thank you in advance.