Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have one procedure in sql server like this:::::
SQL
CREATE PROC SP_FetchData()
as
begin
select FirstName, LastName from TBl_Users;
select TaskId,CreatedBy from TBl_Log;
END;

I want execute the same query in postgres function without using refcursor. how can I do it?

What I have tried:

SQL
CREATE FUNCTION SP_FetchData() RETURNS setof refcursor AS
$$
DECLARE c1 refcursor;
DECLARE c2 refcursor;
BEGIN
    OPEN c1 FOR
    select FirstName, LastName from TBl_Users;
    RETURN NEXT c1;

    OPEN c2 FOR
    select TaskId,CreatedBy from TBl_Log;
    RETURN NEXT c2;
END;
$$ LANGUAGE 'plpgsql';


-- It is working properly but I don't want to use refcursor. How can I do it?
Posted
Updated 24-Apr-18 7:18am
v3

1 solution

As far as I know PostGres does not support multiple result sets without cursors like SQL Server does.

Basically you could join the result sets for example using UNION ALL operation but that would require that the structure and the data types of both results sets are the same. Based on your question, this is not the case.

So if UNION is not a feasible option you probably need to use ref cursors or separate the queries to two different procedures.
 
Share this answer
 
Comments
souviksardar 24-Apr-18 13:23pm    
I don't even need union. I am new to postGres, are you sure it doesn't support multi result set like sql? thnx for your reply

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900