multi recordset and data type check was: Re: PL/pgSQL stored procedure returning multiple result sets (SELECTs)?

From: Ivan Sergio Borgonovo <mail(at)webthatworks(dot)it>
To: pgsql-general(at)postgresql(dot)org
Subject: multi recordset and data type check was: Re: PL/pgSQL stored procedure returning multiple result sets (SELECTs)?
Date: 2008-10-13 11:41:31
Message-ID: 20081013134131.0602b264@dawn.webthatworks.it
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Mon, 13 Oct 2008 12:17:21 +0300
Vladimir Dzhuvinov <vd(at)valan(dot)net> wrote:

> 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;

I'd say returning multiple recordset is useful to save connections
and transferred data.
You can't get the same with a left join (users fields will be
repeated over and over) and you can't get the same with 2 separated
statements since they will need 2 connections.

But from the client side, suppose it PHP... if the first
statement return no record and the second one return 3 records, how
can I know?
What about functions like pg_num_fields?

--
Ivan Sergio Borgonovo
http://www.webthatworks.it

In response to

Browse pgsql-general by date

  From Date Subject
Next Message arnuld uttre 2008-10-13 12:03:24 Re: DB and Unicode problem (was: user and DB confusion)
Previous Message Tino Wildenhain 2008-10-13 11:41:08 Re: DB and Unicode problem (was: user and DB confusion)