Re: PL/pgSQL stored procedure returning multiple result sets (SELECTs)? - Mailing list pgsql-general

From Pavel Stehule
Subject Re: PL/pgSQL stored procedure returning multiple result sets (SELECTs)?
Date
Msg-id 162867790810130235u28d660b4h607d5e713b0a93ad@mail.gmail.com
Whole thread Raw
In response to PL/pgSQL stored procedure returning multiple result sets (SELECTs)?  (Vladimir Dzhuvinov <vd@valan.net>)
Responses Re: PL/pgSQL stored procedure returning multiple result sets (SELECTs)?  (Vladimir Dzhuvinov <vd@valan.net>)
List pgsql-general
2008/10/13 Vladimir Dzhuvinov <vd@valan.net>:
> Hi,
>
> I've got a financial MySQL database where the application accesses data
> through a layer of stored procedures. For various reasons I'm currently
> investigating my options to migrate to another SQL RDBMS.
>
> Postgresql seems to offer a few nice advantages over MySQL (e.g.
> stricter data integrity through checks and constraints, etc.) and I got
> quite excited about it.
>
> However, after consulting the docs and running a few tests, it looks
> like Postgresql misses a crucial feature which my application depends
> upon - returning multiple SELECT result sets from functions/stored
> procedures.
>
> To illustrate, I've got a number of MySQL stored procedures that look
> approximately like this:
>
> CREATE PROCEDURE list_user_accounts(IN user_id INT)
>
>        BEGIN
>
>        -- Return first result set (single row)
>        SELECT * FROM users WHERE id = user_id;
>
>        -- Return second result set (zero or more rows)
>        SELECT * FROM accounts WHERE account_holder = user_id;
>
>        END;
>
>
> So, is it true that as of Postgresql 8.3 there is no way to have a
> pgpqsql function return multiple SELECTs?

Hello,

it's true. You can use setof cursors instead.

http://www.postgresql.org/docs/8.1/static/plpgsql-cursors.html

regards
Pavel Stehule
>
>
> Vladimir Dzhuvinov
>
> --
> Vladimir Dzhuvinov * www.valan.net * PGP key ID AC9A5C6C
>
>

pgsql-general by date:

Previous
From: "A. Kretschmer"
Date:
Subject: Re: PL/pgSQL stored procedure returning multiple result sets (SELECTs)?
Next
From: "arnuld uttre"
Date:
Subject: user and DB confusion