| From: | Борис Мурашов <murasovb(at)gmail(dot)com> |
|---|---|
| To: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> |
| Cc: | Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)com>, pgsql-bugs(at)lists(dot)postgresql(dot)org |
| Subject: | Re: BUG #19906: Backend crash (signal 11) creating a LANGUAGE sql function that returns a composite type from a sub- |
| Date: | 2026-11-16 20:23:02 |
| Message-ID: | CAF_qW9dJpZV0Cv_F3rUh=77dAtQGbMjjEf9v7ng4mz3Ai=cngQ@mail.gmail.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-bugs |
Hi Ayush, Tom,
Thank you both for the quick analysis.
I understand the decision to add the NULL check in
coerce_record_to_complex(). This form has never worked, and the workaround
is simple.
One request from the user side: the new error "cannot cast type record to
t" does not help much here. The function body looks correct, and the same
query works as a plain SELECT, so it is not clear what to change. Is it
possible to add an errhint() that tells the user to cast the row
explicitly, for example "Cast the row value to type t explicitly"? This
hint shows users the s::t workaround at once.
If a patch is available, I can test it on 18.x with our original query.
Regards,
Boris
пн, 16 нояб. 2026 г. в 21:29, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>:
> Ayush Tiwari <ayushtiwari(dot)slg01(at)gmail(dot)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
>
--
SDH "StudentDrawingHelper"
Aircraft engineer
Boris Murasov
Mob.: +370 63586809
E-mail: murasovb(at)gmail(dot)com
E-mail2: sdh(at)drawinghelper(dot)eu
WEB: www.drawinghelper.eu
<http://www.camcons.lt>
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Michael Malis | 2026-11-16 20:28:08 | Hot Standby: missing snapshot conflicts in CREATE INDEX, rewrite, hash |
| Previous Message | David Rowley | 2026-11-16 20:16:55 | Re: PG 18 JIT regression: int4range hash breaks multi-key GROUP BY |