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.98.2) (envelope-from ) id 1xSyVl-000000000RB-3LFk for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Nov 2026 15:20:50 +0000 Received: from localhost ([127.0.0.1]:53100 helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xSyVk-00000001q9L-3EBb for pgsql-bugs@arkaria.postgresql.org; Mon, 16 Nov 2026 15:20:48 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]:47768) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xSf89-0000000Fs9q-3RBs for pgsql-bugs@lists.postgresql.org; Sun, 15 Nov 2026 18:39:10 +0000 Received: from mahout.postgresql.org ([2001:4800:3e1:1::227]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xSf86-00000001Cko-31tp for pgsql-bugs@lists.postgresql.org; Sun, 15 Nov 2026 18:39:09 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=postgresql.org; s=20171124; h=Message-ID:Date:Reply-To:Cc:From:To:Subject: Content-Transfer-Encoding:MIME-Version:Content-Type:Sender:Content-ID: Content-Description:In-Reply-To:References; bh=TQM1+ConykPtJ8O6QqJ+BpoStm6fcxbeg8Zt1L2NdeE=; b=QNOdeb5ltEBckNXgiQkHxeDRSY 8tGsLqsBJcMRaNOJ+lEnmpRY30gbdBbhLrFTetZxGGXrG2YzwP9BbY79RZgwqfi6x0T/dagckiGH/ 4vADviv7Zy8X9NFEEtpW8J5U89+vxCY+aMHjsCAekz03zV4YTK4r7myQHXu/4s0kPs/IaQr9Axccn CCoShDUdJ73RG/qP2ZwT6owHFGueZDgxcuRDdIF3IyUXqssmBgakFTZTk0T9uUpK0Lnj+8s+I8bPx tbhBl/iQscIvZgR7aw7rt305Q2YuYI7H1ot4RmDybll5P7kDQEHGEQ8e9qQZPQ5AzrnfbpJp1q4+F 96p5r/nA==; Received: from wrigleys.postgresql.org ([2a02:16a8:dc51::60]) by mahout.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.98.2) (envelope-from ) id 1xSf84-000000034Bh-0GpC for pgsql-bugs@lists.postgresql.org; Sun, 15 Nov 2026 18:39:04 +0000 Received: from localhost ([127.0.0.1] helo=wrigleys.postgresql.org) by wrigleys.postgresql.org with esmtp (Exim 4.98.2) (envelope-from ) id 1xSf83-00000007f9F-1OPA for pgsql-bugs@lists.postgresql.org; Sun, 15 Nov 2026 18:39:03 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #19906: Backend crash (signal 11) creating a LANGUAGE sql function that returns a composite type from a sub- To: pgsql-bugs@lists.postgresql.org From: PG Bug reporting form Cc: murasovb@gmail.com Reply-To: murasovb@gmail.com, pgsql-bugs@lists.postgresql.org Date: Sun, 15 Nov 2026 18:38:20 +0000 Message-ID: <19906-229033275b593ef0@postgresql.org> X-Auto-Response-Suppress: All Auto-Submitted: auto-generated List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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: =20 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 =3D 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 =3D off, create function 1, then SELECT * FR= OM 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.