Re: Postgres function with output parameters and resultset - Mailing list pgsql-general

From David G. Johnston
Subject Re: Postgres function with output parameters and resultset
Date
Msg-id CAKFQuwbZYHvHjk6ET97X=-DSTTtvarAmR6a2hG1rH4OmdeAeFA@mail.gmail.com
Whole thread Raw
In response to Postgres function with output parameters and resultset  (Arulalan Narayanasamy <arulalan.narayanasamy@gmail.com>)
List pgsql-general
On Friday, July 20, 2018, Arulalan Narayanasamy <arulalan.narayanasamy@gmail.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.

pgsql-general by date:

Previous
From: Arulalan Narayanasamy
Date:
Subject: Postgres function with output parameters and resultset
Next
From: Adrian Klaver
Date:
Subject: Re: Postgres function with output parameters and resultset