Question: Return query result from postgresql conditionally

Question

Return query result from postgresql conditionally

Answers 0
Added at 2016-11-28 23:11
Tags
Question

I am trying to write function that should return records based on my input parameter. Structure will differ based on input. Here is something similar I am trying to achieve:

begin
    case option
        when 1 then 
            return query select column1, column2 from table1;
        when 2 then 
            return query select columns2, column4, column5 from table2;
        else 
            return query select .....;
    end case;
end $$;

I want my users to just call my function like this: Select * from myfunction(1);

Not sure what is simple and clean way to achieve this.

Answers to

Return query result from postgresql conditionally

Source Show
◀ Wstecz