Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t2jNc-006eID-2v for pgsql-general@arkaria.postgresql.org; Mon, 21 Oct 2024 03:46:52 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1t2jNZ-0043O0-5v for pgsql-general@arkaria.postgresql.org; Mon, 21 Oct 2024 03:46:49 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t2jNY-0043Nr-R6 for pgsql-general@lists.postgresql.org; Mon, 21 Oct 2024 03:46:49 +0000 Received: from sss.pgh.pa.us ([68.162.161.243]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1t2jNW-001wJb-FD for pgsql-general@lists.postgresql.org; Mon, 21 Oct 2024 03:46:47 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 49L3kiuI1445999; Sun, 20 Oct 2024 23:46:44 -0400 From: Tom Lane To: Michel Pelletier cc: pgsql-general Subject: Re: Using Expanded Objects other than Arrays from plpgsql In-reply-to: References: <1342498.1729444411@sss.pgh.pa.us> Comments: In-reply-to Michel Pelletier message dated "Sun, 20 Oct 2024 20:29:13 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <1445997.1729482404.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Sun, 20 Oct 2024 23:46:44 -0400 Message-ID: <1445998.1729482404@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Michel Pelletier writes: > On Sun, Oct 20, 2024 at 10:13=E2=80=AFAM Tom Lane wr= ote: >> 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_e= xec.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