Reputation: 21
I want to create a plpgsql function that will execute a simple select query,i.e. "Select * from table name" .When i will run that function by this query which is like "select function()",then it will return the output as "Select * from table name".
Upvotes: 1
Views: 280
Reputation:
No need for a PL/pgSQL function. A simple SQL function will do:
create or replace function get_result()
returns setof table_name
as
$$
select * from table_name;
$$
language sql;
But you need to use select * from function();
to get the result not select function()
because set returning functions can only be used in the from
clause.
Upvotes: 1