pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Ayush Tiwari <ayushtiwari.slg01@gmail.com>
Cc: murasovb@gmail.com
Cc: pgsql-bugs@lists.postgresql.org
Subject: Re: BUG #19906: Backend crash (signal 11) creating a LANGUAGE sql function that returns a composite type from a sub-
Date: Mon, 16 Nov 2026 14:28:59 -0500
Message-ID: <126458.1794857339@sss.pgh.pa.us> (raw)
In-Reply-To: <CAJTYsWUm1j=YQsHpt12=E_Xmx7GhtmVtRAZ2x+ySOo3bkJtWyQ@mail.gmail.com>
References: <19906-229033275b593ef0@postgresql.org>
	<CAJTYsWUm1j=YQsHpt12=E_Xmx7GhtmVtRAZ2x+ySOo3bkJtWyQ@mail.gmail.com>

Ayush Tiwari <ayushtiwari.slg01@gmail.com> writes:
> The crash can be fixed by checking for pstate not being NULL in
> coerce_record_to_complex(), which makes it error out with "cannot cast
> type record to t". But I'm unsure if we should do just that, or rather
> teach check_sql_fn_retval() to expand the whole-row Var so that this
> works like s::t?

Yeah, I was just looking at this too.  It's been a crash case since
v13, and before that you got

ERROR:  return type mismatch in function declared to return t
DETAIL:  Final statement returns record instead of integer at column 1.
CONTEXT:  SQL function "m1"

So it's never worked, and there's been no complaints to speak of,
and it's easy to work around:

  CREATE FUNCTION m1() RETURNS TABLE (x t) LANGUAGE sql
    AS $$ SELECT s::t FROM (SELECT t.* FROM t) s $$;

So I think that putting in a defense against null pstate in
coerce_record_to_complex() is sufficient.  Making it work would be
very very tedious (I don't think we have any prefab code that
would be suitable) and evidently there's no demand.

Actually the annoying part of this is that we ought to change the
comments elsewhere in parse_coerce.c that say that pstate is only
used to return data about Param types, because that's evidently a
lie (and has been since well before v13...).

			regards, tom lane






view thread (9+ messages)  latest in thread

Message-ID: <126458.1794857339@sss.pgh.pa.us>
Permalink:  ../126458.1794857339@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/126458.1794857339@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 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-bugs@postgresql.org
  Cc: tgl@sss.pgh.pa.us, ayushtiwari.slg01@gmail.com, murasovb@gmail.com
  Subject: Re: BUG #19906: Backend crash (signal 11) creating a LANGUAGE sql function that returns a composite type from a sub-
  In-Reply-To: <126458.1794857339@sss.pgh.pa.us>
  References: <19906-229033275b593ef0@postgresql.org> <CAJTYsWUm1j=YQsHpt12=E_Xmx7GhtmVtRAZ2x+ySOo3bkJtWyQ@mail.gmail.com> <126458.1794857339@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