pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17669: Invalid TOAST pointer in PL/pgSQL variable
3+ messages / 3 participants
[nested] [flat]

* BUG #17669: Invalid TOAST pointer in PL/pgSQL variable
@ 2022-10-27 19:45 PG Bug reporting form <noreply@postgresql.org>
  2022-10-28 13:43 ` Re: BUG #17669: Invalid TOAST pointer in PL/pgSQL variable Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 3+ messages in thread

From: PG Bug reporting form @ 2022-10-27 19:45 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: s.shinderuk@postgrespro.ru

The following bug has been logged on the website:

Bug reference:      17669
Logged by:          Sergey Shinderuk
Email address:      s.shinderuk@postgrespro.ru
PostgreSQL version: 15.0
Operating system:   Ubuntu 22.04
Description:        

Is it a bug or a known limitation?

create table t (a int, b text);
alter table t alter column b set storage external;
insert into t values (1, repeat('a',3000));

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

If I replace "truncate" with "drop table", then I get:
ERROR:  could not open relation with OID 24725

With "delete from t" it just works.



^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #17669: Invalid TOAST pointer in PL/pgSQL variable
  2022-10-27 19:45 BUG #17669: Invalid TOAST pointer in PL/pgSQL variable PG Bug reporting form <noreply@postgresql.org>
@ 2022-10-28 13:43 ` Tom Lane <tgl@sss.pgh.pa.us>
  2022-10-28 14:16   ` Re: BUG #17669: Invalid TOAST pointer in PL/pgSQL variable Sergey Shinderuk <s.shinderuk@postgrespro.ru>
  0 siblings, 1 reply; 3+ messages in thread

From: Tom Lane @ 2022-10-28 13:43 UTC (permalink / raw)
  To: s.shinderuk@postgrespro.ru; +Cc: pgsql-bugs@lists.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





^ permalink  raw  reply  [nested|flat] 3+ messages in thread

* Re: BUG #17669: Invalid TOAST pointer in PL/pgSQL variable
  2022-10-27 19:45 BUG #17669: Invalid TOAST pointer in PL/pgSQL variable PG Bug reporting form <noreply@postgresql.org>
  2022-10-28 13:43 ` Re: BUG #17669: Invalid TOAST pointer in PL/pgSQL variable Tom Lane <tgl@sss.pgh.pa.us>
@ 2022-10-28 14:16   ` Sergey Shinderuk <s.shinderuk@postgrespro.ru>
  0 siblings, 0 replies; 3+ messages in thread

From: Sergey Shinderuk @ 2022-10-28 14:16 UTC (permalink / raw)
  To: Tom Lane <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs@lists.postgresql.org

On 28.10.2022 16:43, Tom Lane wrote:
> PG Bug reporting form <noreply@postgresql.org> writes:
>> 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.
Thank you for explaining.

-- 
Sergey Shinderuk		https://postgrespro.com/






^ permalink  raw  reply  [nested|flat] 3+ messages in thread


end of thread, other threads:[~2022-10-28 14:16 UTC | newest]

Thread overview: 3+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-10-27 19:45 BUG #17669: Invalid TOAST pointer in PL/pgSQL variable PG Bug reporting form <noreply@postgresql.org>
2022-10-28 13:43 ` Tom Lane <tgl@sss.pgh.pa.us>
2022-10-28 14:16   ` Sergey Shinderuk <s.shinderuk@postgrespro.ru>

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