pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: s.shinderuk@postgrespro.ru
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #17669: Invalid TOAST pointer in PL/pgSQL variable
Date: Fri, 28 Oct 2022 09:43:00 -0400
Message-ID: <1195625.1666964580@sss.pgh.pa.us> (raw)
In-Reply-To: <17669-2238da15dce5c53c@postgresql.org>
References: <17669-2238da15dce5c53c@postgresql.org>

PG Bug reporting form <noreply@postgresql.org> writes:
> create function f() returns text as $$
> declare
>   s text;
> begin
>   select b into s from t where a = 1;
>   truncate t;
>   return s;
> end;
> $$ language plpgsql;

> postgres=# select f();
> ERROR:  missing chunk number 0 for toast value 24727 in pg_toast_24722

To prevent that, every fetch into a plpgsql variable would have
to immediately detoast the value, in case somebody did something
as weird as dropping/truncating the table later in the function.
That's an awfully expensive bit of protection.  We do in fact
do it like that in procedures (more specifically, in non-atomic
contexts), so a possible workaround for you is to make this a
procedure not a function.  I'm disinclined to change it otherwise.

			regards, tom lane





view thread (3+ messages)  latest in thread

Message-ID: <1195625.1666964580@sss.pgh.pa.us>
Permalink:  ../1195625.1666964580@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/1195625.1666964580@sss.pgh.pa.us

 · 

reply

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 using the --to and --cc options:
  reply via email

  To: pgsql-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, s.shinderuk@postgrespro.ru, pgsql-bugs@lists.postgresql.org
  Subject: Re: BUG #17669: Invalid TOAST pointer in PL/pgSQL variable
  In-Reply-To: <1195625.1666964580@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