I have this function in PostgreSQL:
CREATE OR REPLACE FUNCTION func1(a integer, b timestamp, c integer[])
RETURNS SETOF typ_new AS
$BODY$
declare
begin
CREATE OR REPLACE VIEW newView as (select * from func2($1,$2,$3));
end;
$BODY$
LANGUAGE plpgsql VOLATILE
func2also returns SETOF typ_newto be compatible.
When I start, I get an error: ERROR: there is no parameter $1
if I changed $1to the parameter name a, then the error will change to
ERROR: column "a" does not exist
I also tried dynamic SQL:
sqlstr ='CREATE OR REPLACE VIEW newView (columns... ) as
(select * from func2('||$1||','||$2||','||$3||'))';
execute sqlstr;
but it does not work, because there $3is integer[]and ||cannot work with arrays.
How to solve this?
source
share