From: Tom Lane <tgl@sss.pgh.pa.us>
To: Nick Renders <postgres@arcict.com>
Cc: pgsql-general <pgsql-general@postgresql.org>
Subject: Re: PL/pgSQL question about EXCEPTION clause & corrupt records
Date: Fri, 14 Feb 2020 10:14:38 -0500
Message-ID: <16417.1581693278@sss.pgh.pa.us> (raw)
In-Reply-To: <4DF3093D-C58F-4DC5-BE22-49F4D9630594@arcict.com>
References: <4DF3093D-C58F-4DC5-BE22-49F4D9630594@arcict.com>
"Nick Renders" <postgres@arcict.com> writes:
> I thought I would write a little PL script that would loop through all
> the data and report any inconsistencies. However, I can't get it to work
> properly.
> ...
> 1) The function has no problem executing the SELECT statement. It is
> only when "rcontents" is returned, that the function fails. This is a
> problem, because the ultimate goal is to loop through all records and
> only return/alert something in case of an error.
> 2) The function never enters the EXCEPTION clause. Instead, when it hits
> the RETURN command, it breaks and shows the same message as in pgAdmin:
> missing chunk number 0 for toast value 8289525 in pg_toast_5572299.
I think what's happening there is that the function doesn't try to
dereference the value's TOAST pointer during SELECT INTO. It just stores
that pointer into a variable, and only sometime later when the actual
content of the value is demanded, do you see the error raised.
The solution to that is to do something that uses the contents of the
busted column right away while still inside the EXCEPTION block, perhaps
along the lines of "select md5(mycolumn) into local_variable from..."
A close reading of
https://www.postgresql.org/docs/current/storage-toast.html
would probably help you understand what's happening here.
regards, tom lane
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-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, postgres@arcict.com
Subject: Re: PL/pgSQL question about EXCEPTION clause & corrupt records
In-Reply-To: <16417.1581693278@sss.pgh.pa.us>
References: <4DF3093D-C58F-4DC5-BE22-49F4D9630594@arcict.com> <16417.1581693278@sss.pgh.pa.us>
* 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