Re: Using Expanded Objects other than Arrays from plpgsql

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Michel Pelletier <pelletier(dot)michel(at)gmail(dot)com>
Cc: pgsql-general <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Using Expanded Objects other than Arrays from plpgsql
Date: 2024-10-21 03:46:44
Message-ID: 1445998.1729482404@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general pgsql-hackers

Michel Pelletier <pelletier(dot)michel(at)gmail(dot)com> writes:
> On Sun, Oct 20, 2024 at 10:13 AM Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:
>> But it seems like we could get an easy win by adjusting
>> plpgsql_exec_function along the lines of
>> ...

> I tried this change and couldn't get it to work, on the next line:
> if (VARATT_IS_EXTERNAL_EXPANDED_RW(DatumGetPointer(var->value)))
> var->value might not be a pointer, as it seems at least from my gdb
> scratching, but say an integer. This segfaults on non-array but
> non-expandable datum.

Oh, duh --- the typisarray test serves to eliminate pass-by-value
types. We need the same test that exec_assign_value makes,
!var->datatype->typbyval, before it's safe to apply DatumGetPointer.
So line 549 needs to be more like

- if (!var->isnull && var->datatype->typisarray)
+ if (!var->isnull && !var->datatype->typbyval)

> Another comment that caught my eye was this one:
> https://github.com/postgres/postgres/blob/master/src/pl/plpgsql/src/pl_exec.c#L8304
> Not sure what the implication is there.

Yeah, that's some more unfinished business. I'm not sure if it
matters to your use-case or not.

BTW, we probably should move this thread to pgsql-hackers.

regards, tom lane

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message user 2024-10-21 08:40:12 Fwd: Postgres attach partition: AccessExclusive lock set on different tables depending on how attaching is performed
Previous Message Michel Pelletier 2024-10-21 03:29:13 Re: Using Expanded Objects other than Arrays from plpgsql

Browse pgsql-hackers by date

  From Date Subject
Next Message shveta malik 2024-10-21 05:03:32 Re: Conflict Detection and Resolution
Previous Message vignesh C 2024-10-21 03:37:21 Re: Pgoutput not capturing the generated columns