functions – How do I make postgresql resolve parametrized schema?


I’m looking for a way to use parametrized schema in DECLARE section on Postgresql Function.

Here is an example:

CREATE OR REPLACE FUNCTION get_list(in_code text(), p_schema text)
  RETURNS text  AS
$func$

DECLARE

  var1 user.emp%ROWTYPE;

BEGIN

SELECT q.id, q.title, q.code
FROM   questions q
WHERE  q.code <> ALL ($1);

END ;

$func$ LANGUAGE sql;

The above getting created.

When I change var1 user.emp%ROWTYPE; to

var1 p_schema.emp%ROWTYPE; or
var1 $$ || p_schema || $$.emp%ROWTYPE;

Function is not getting created, but throwing error

ERROR : relation emp not found

Are there any limitation of using parameterized items within DECLARE section?

I used this kind of parameters with queries within BEGIN & END section. It did not throw any errors.

Thanks for sharing.