Re: Postgres function with output parameters and resultset

From: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>
To: Arulalan Narayanasamy <arulalan(dot)narayanasamy(at)gmail(dot)com>
Cc: "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Postgres function with output parameters and resultset
Date: 2018-07-20 21:36:46
Message-ID: CAKFQuwbZYHvHjk6ET97X=-DSTTtvarAmR6a2hG1rH4OmdeAeFA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Friday, July 20, 2018, Arulalan Narayanasamy <
arulalan(dot)narayanasamy(at)gmail(dot)com> wrote:

> Hi,
> I need to create a function which should return resultset and output
> parameters. For example, I need to retrieve all the records from EMP table
> whose Grade is 'A' as resultset and total number of matched records,
> Success or Failure flag & Error message as output parameters. Is there a
> way in Postgres to achieve this? Kindly help!!
>

A function can return a single two dimensional table - so, not directly.
Though what you describe here seems like over-engineering. If you really
want the count you'd need to add it to the table but the client can count
the records in the table easily enough. Errors can be done separately via
RAISE and likewise let the client deal with that as usual.

Otherwise I've found JSON to be useful for non-tabular results.

David J.

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2018-07-20 21:50:58 Re: Postgres function with output parameters and resultset
Previous Message Arulalan Narayanasamy 2018-07-20 21:19:35 Postgres function with output parameters and resultset