Can a PL/pgSQL function contain a dynamic subquery?

Posted by morpheous on Stack Overflow See other posts from Stack Overflow or by morpheous
Published on 2010-05-17T07:38:15Z Indexed on 2010/05/17 7:40 UTC
Read the original article Hit count: 269

Filed under:
|

I am writing a PL/pgSQL function. The function has input parameters which specify (indirectly), which tables to read filtering information from.

The function embeds business logic which allows it to select data from different tables based on the input arguments. The function dynamically builds a subquery which returns filtering data which is then used to run the main query.

My questions are:

  1. Is it 'legal' to use a dynamic subquery in a PL/pgSQL function. I cant see why not - but this question is related to the next one.

  2. AFAIK, PL/pgSQL are cached or precompiled by the query engine. How does having a function that generates dynamic subqueries impact the work of the query engine?

© Stack Overflow or respective owner

Related posts about postgresql

Related posts about plpgsql