From: Skylar Thompson <skylar2@uw.edu>
To: pgsql-sql@lists.postgresql.org
Subject: Re: Try catch error, return data
Date: Tue, 15 Feb 2022 19:08:46 -0800
Message-ID: <20220216030846.v7g4ggin5om7xwpu@hithlum> (raw)
In-Reply-To: <CA+i5Jwbf0OUut+aMSAi4o+CuPc3aV6rQpnCD6xYjSZX5CAM3Cg@mail.gmail.com>
References: <CA+i5Jwbf0OUut+aMSAi4o+CuPc3aV6rQpnCD6xYjSZX5CAM3Cg@mail.gmail.com>
I think you're looking for EXCEPTION:
https://www.postgresql.org/docs/14/plpgsql-control-structures.html#PLPGSQL-ERROR-TRAPPING
At the point you've trapped the error, you can then return something based
on the error. You can find a list of exception codes in one of the
appendices:
https://www.postgresql.org/docs/14/errcodes-appendix.html
On Wed, Feb 16, 2022 at 02:13:05AM +0000, Shaozhong SHI wrote:
> In Python, one can use try statement to catch error, error can be stored as
> data.
>
> Can plpgsql catch and return error as data or a data table?
>
> Regards, David
--
-- Skylar Thompson (skylar2@u.washington.edu)
-- Genome Sciences Department (UW Medicine), System Administrator
-- Foege Building S046, (206)-685-7354
-- Pronouns: He/Him/His
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-sql@postgresql.org
Cc: skylar2@uw.edu
Subject: Re: Try catch error, return data
In-Reply-To: <20220216030846.v7g4ggin5om7xwpu@hithlum>
References: <CA+i5Jwbf0OUut+aMSAi4o+CuPc3aV6rQpnCD6xYjSZX5CAM3Cg@mail.gmail.com> <20220216030846.v7g4ggin5om7xwpu@hithlum>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox