Question

For example: I have a VIEW called "view1" which contains 'name' and 'slno' columns, now i want it to be display using FUNCTION called "f1" as shown below:

--Function

create or replace function f1(viewname varchar) 
returns table (name varchar,slno integer) as
$body$
begin
     return query
     select * from viewname;
end;
$body$
language plpgsql;
Was it helpful?

Solution

This is dynamic SQL, so you need EXECUTE.

RETURN QUERY EXECUTE format('SELECT * FROM %I', "name");

Separately, that's a weird thing to want to do.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top