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
func2 also returns SETOF typ_new so they are compatible.
When running it I get an error : ERROR: there is no parameter $1
if I change the $1 to the parameter name a then the error changes 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 doesn't work because $3 is integer[] and || can't work with arrays.
How do I solve this?
EXECUTEand theformatparameter. See many related answers for details.VIEW as $BODY$and make function select from this view?