0

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;

1 Answer 1

6

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.