I need to create a function which should returns a select statement result from it.
Example:
Create or replace function fun_test(cola text,colb text,rel text)
returns table(columna text,columnb text)as
$Body$
Declare
table_name varchar :='Table_';
temp_t record;
Begin
table_name := table_name || rel;
raise info '%',table_name;
execute 'select distinct'||quote_ident(cola)||','||quote_ident(colb)|| ' from '||quote_ident(table_name) into temp_t;
return query select * from temp_t; /* Error relation "temp_t" does not exist
/* Here I need to update temp_t also*/
end;
$Body$
language plpgsql;
Error:
ERROR: relation "temp_t" does not exist
LINE 1: select * from temp_t
^
SELECT FROMfrom aRECORDvariable. What are you trying to achieve here? You can't do anything after youRETURN QUERY, that exits the procedure. None of this makes any sense. Have you read the examples in the documentation?selectresult into table and need to update that table.select intostatement.SELECT INTOa table. Are you looking forINSERT INTO ... SELECT ...?select numb,rank into temp_t from myview;to be done there.