Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return multiple rows from plpgsql function

I have the below function:

CREATE OR REPLACE FUNCTION function1() RETURNS TABLE(foo1 VARCHAR, foo2 VARCHAR) AS $$
    BEGIN
    RETURN QUERY SELECT e.col1, e.col2 FROM my_table e;
    END;
$$ LANGUAGE plpgsql;

It returns something like this:

function1
record
|--------------|
(a,b)
(c,d)

But I'm expecting a result analog to a query like this:

SELECT e.col1, e.col2 FROM my_table e;

  col1  col2
|-----|-----|
   a     b
   c     d

Because I want to execute the function a get the separates columns values in a java resultSet and iterate accros them. Thanks!

like image 710
Diego Quirós Avatar asked Aug 31 '13 23:08

Diego Quirós


1 Answers

You need to do

select * from function1();
like image 124
sega_sai Avatar answered Oct 13 '22 13:10

sega_sai