BUG #19906: Backend crash (signal 11) creating a LANGUAGE sql function that returns a composite type from a sub-

From: PG Bug reporting form <noreply(at)postgresql(dot)org>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Cc: murasovb(at)gmail(dot)com
Subject: BUG #19906: Backend crash (signal 11) creating a LANGUAGE sql function that returns a composite type from a sub-
Date: 2026-11-15 18:38:20
Message-ID: 19906-229033275b593ef0@postgresql.org
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

The following bug has been logged on the website:

Bug reference: 19906
Logged by: Boris
Email address: murasovb(at)gmail(dot)com
PostgreSQL version: 18.7
Operating system: Debian 13 (trixie), x86_64, Docker image pgvector/
Description:

PostgreSQL version:
PostgreSQL 18.7 (Debian 18.7-1.pgdg13+2) on x86_64-pc-linux-gnu, compiled by
gcc (Debian 14.2.0-19) 14.2.0, 64-bit
(official Debian package in the pgvector/pgvector:0.8.7-pg18-trixie Docker
image; default configuration; empty database)

Minimal reproduction:

CREATE TABLE t (id int, v text);
CREATE FUNCTION m1() RETURNS TABLE (x t) LANGUAGE sql
AS $$ SELECT s FROM (SELECT t.* FROM t) s $$;

Result: "server closed the connection unexpectedly". The server log shows:
client backend (PID ...) was terminated by signal 11: Segmentation fault
and the postmaster runs crash recovery.

The CREATE FUNCTION alone crashes (check_function_bodies = on). The table
can be empty.

Variations (one change at a time):

1. RETURNS TABLE (x t), body SELECT s FROM (SELECT t.* FROM t) s
-> crash
2. RETURNS SETOF t, same body
-> crash
3. RETURNS TABLE (x t), body SELECT t FROM t (whole row of the table
itself) -> OK
4. RETURNS TABLE (n int, x t), body SELECT 1, s FROM (SELECT t.* FROM t) s
-> crash
5. RETURNS t (single row), body of 1
-> crash
6. SET check_function_bodies = off, create function 1, then SELECT * FROM
m1() -> crash at the call
7. Same body in LANGUAGE plpgsql with RETURN QUERY
-> error "structure of query does not match function result type", no crash
8. Plain statement SELECT s::t FROM (SELECT t.* FROM t) s
-> OK
9. RETURNS TABLE (x t), body SELECT ROW(s.*) FROM (SELECT t.* FROM t) s
-> OK
10. RETURNS TABLE (id int, v text), body SELECT s.id, s.v FROM (SELECT t.*
FROM t) s -> OK
11. RETURNS SETOF t, body SELECT s FROM (SELECT id, v FROM t) s
-> crash

Summary: a LANGUAGE sql function whose result (a column, SETOF, or a single
row) is a named composite type,
and whose final SELECT returns the whole-row reference of a sub-select in
FROM (a value of type record that
must be converted to that composite type), crashes the backend. PL/pgSQL
reports an error instead.
SET clauses, SECURITY INVOKER/DEFINER, volatility and ROWS are not needed to
trigger it.

Workaround: return explicit columns, or ROW(s.*), instead of the bare
whole-row reference.

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message shveta malik 2026-11-16 03:54:10 Re: BUG #19864: pg_get_publication_tables() gets cache lookup error after concurrent DROP PUBLICATION
Previous Message 민영재 2026-11-15 16:22:24 Re: BUG #19736: `JSON_OBJECT ... ABSENT ON NULL` accepts invalid keys when the value is NULL