Thread: Table as parameter

Table as parameter

From
Alex Paulo
Date:
Friends of pgsql-general list,

I have a problem: I need put the "table name" as a parameter in a function!
So, When I write, inside that function, the following code:

SELECT INTO var_resposta SUM(campo) FROM $1
return var_resposta;

Knows that $1 is the table name, the postgres said that this is a sintax error, exactly at $1 position!
Somebody can help me?

Thank you for taking the time!

Best Regards, Alex Paulo.

R: Table as parameter

From
Scara Maccai
Date:
> I have a problem: I need put the "table name" as
> a parameter in a function!

I think you have to use dynamic statements:

http://www.postgresql.org/docs/8.4/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-EXECUTING-DYN






Re: Table as parameter

From
Grzegorz Jaśkiewicz
Date:
look at EXECUTE in plpgpsql.