pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: PG Bug reporting form <noreply@postgresql.org>
To: pgsql-bugs@lists.postgresql.org
Cc: murasovb@gmail.com
Subject: BUG #19906: Backend crash (signal 11) creating a LANGUAGE sql function that returns a composite type from a sub-
Date: Sun, 15 Nov 2026 18:38:20 +0000
Message-ID: <19906-229033275b593ef0@postgresql.org> (raw)

The following bug has been logged on the website:

Bug reference:      19906
Logged by:          Boris
Email address:      murasovb@gmail.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.








view thread (9+ messages)  latest in thread

Message-ID: <19906-229033275b593ef0@postgresql.org>
Permalink:  ../19906-229033275b593ef0@postgresql.org/
Also on:    postgresql.org/message-id/19906-229033275b593ef0@postgresql.org

 · 

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: noreply@postgresql.org, 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: <19906-229033275b593ef0@postgresql.org>
  References: <19906-229033275b593ef0@postgresql.org>

* 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