title: PostgreSQL: How to use SELECT statement within CASE expression in function?
body: <p>Can we able to use SELECT statement within CASE conditional expression in function?<br>
  I have tried the following function to accomplish the above task.  </p>
  
  <p>Example: I have a function which is used to display table containing some rows.  </p>
  
  <pre><code>create or replace function test(n integer) 
  returns table (name text,city text) as
  $body$
  begin
       case n when 1 then
       select * from table1
  
       when 2 then
       select * from table2
  
       when 3 then
       select * from view1
  
       end;
  end;
  $body$
  language plpgsql;
  </code></pre>
  
  <p>--Calling function  </p>
  
  <pre><code>select * from test(1);  
  /*have to show details of table1*/
  
  select * from test(2);
  /*have to show details of table2*/
  
  select * from test(3);
  /*have to display details of view1*/
  </code></pre>