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.96) (envelope-from ) id 1x6IMs-00099x-1h for pgsql-bugs@arkaria.postgresql.org; Tue, 15 Sep 2026 01:53:54 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1x6IMr-00Gcp9-1q for pgsql-bugs@arkaria.postgresql.org; Tue, 15 Sep 2026 01:53:53 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1x6IMr-00GcoP-14 for pgsql-bugs@lists.postgresql.org; Tue, 15 Sep 2026 01:53:53 +0000 Received: from mail-qk1-x736.google.com ([2607:f8b0:4864:20::736]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1x6IMp-0000000072p-0r6e for pgsql-bugs@lists.postgresql.org; Tue, 15 Sep 2026 01:53:52 +0000 Received: by mail-qk1-x736.google.com with SMTP id af79cd13be357-93a10f9a2easo41622785a.0 for ; Mon, 14 Sep 2026 18:53:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1789437230; x=1790042030; darn=lists.postgresql.org; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:from:to:cc :subject:date:message-id:reply-to:content-type; bh=CxXZ97W59FL6ICrvJ0EIXQ3jpchctEcNcICh8JJPS4I=; b=OX7Qr1lFcrhpq8G3LADVOHDWaUArjz2z1Mq9AnRHq4vS2PhMGWXRGsoSEBsko028mM 4D0S6Gqw6Es/AiaUewWz3AJjvRqSlSuSpfGNWz+wCFng9oy/URJxr3w6Hlat9lYZNeGw 5/NMOdR8VGPZjtPQsr612id2pu0s9JqalmXpTQdEFo/c938s/xdvJcgqyVdF4QGx+JIz 5+fuV9rTqZFZJvVTLp2kh1BnbTJXnVlWIEQkB3CnITbiiTT12wQP1PwRQDWC0UjuEsMk OymTSw0ReztJrmOVacKfZ3qdnpixht4DV+5+8Wg4erGVfW3htwL1zBm9FHX7iFqN7slM GDAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1789437230; x=1790042030; h=to:references:message-id:content-transfer-encoding:cc:date :in-reply-to:from:subject:mime-version:content-type:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=CxXZ97W59FL6ICrvJ0EIXQ3jpchctEcNcICh8JJPS4I=; b=qrWRSxXmFzYnczgIAQ9g4946n4dnIyIdZQrK57ygDVqrwX/br7kuJLnST+Rqcr9xiG 6E1pw8Izsc0fuuf2ET6hf+3Zs4MkODyvULgl+o/GKhpoHB9StZtZMHGz9ddNJTQa5GVt tDg9JJYdxYNgzXSmXjfCtLNzIh06xG0vcQQmWQIgOXKUQpdMY+qyXFLR05Pe5lbqyNxB hwvIYCYvoYb4W2PlbGMtLPK7DfTSf++iSKa20463YSODAoNbpxufBw6UFh6jpJhfNHcs +Bx+wp2yMlb0EVKWNbu49hMozZHp2aPxnPlY7I5JEKqYrWwwm3by7DGFrADOY8MkbhNI 1Umg== X-Gm-Message-State: AFuF++lL1mbflUcMbvLyJqIw1yzc16+rez2RjzTRplNlFJliMBSRbmxl nzHmbU0m/+GUiMSc6bCNGHRRjBLMoPM6EPSeRfzzadFXl7/VZ+Gro4QK X-Gm-Gg: AYBFou0pKRH9Kt3REq+W79gNZqLg+xxVqtP98DDSHQ5T6V7iX3vuzJlTKNkXFr4M/lP jziWaxkNmCxFn0kUgYFvuI/5EkOvHzrj9coVUh9hJtjVC8icW6ZzfeUKKtfNG3ZK2OHojU3FJ+g qZOdEb0LrQTi7KQ5r3c5/PY2qteFKlp2ppqNJW3Kbg3z/HCbur+VXPoxwSqXNqAjoN4NEmVgG0B XGFUPCtb4kVUQlZ68L7jByUh5aJvRm1cMcz3+K6fUwPl0RDpuz+E8ux+92UkLeXH4ZiMCy6ECbP weqgvV8+CIv8QqDNRoeZ185nrwhFvK4NgY6dU86SXMce0UmQFGA1eK9aYUNcYwP6i0G6RjdSpls 1suLXSdFmPuqo1AuYBmUk9giWMVgoDs1X0pqUyezcXFGlbmLduGvH6lkI+I2J/Ioy7AivIC0g6r XxA0E4o3GlWY3sMYB0+C1rf8GhMJwOZbrX7hMs27ViybRZYX0u6Yzzjs0+7vv0ms6ARx1qRsvO/ EF5NvTlbLiaLg== X-Received: by 2002:a05:620a:6609:b0:939:b783:1748 with SMTP id af79cd13be357-93a345d7062mr259404085a.7.1789437230066; Mon, 14 Sep 2026 18:53:50 -0700 (PDT) Received: from smtpclient.apple ([67.103.169.62]) by smtp.gmail.com with ESMTPSA id 6a1803df08f44-9120f47afc2sm108990916d6.20.2026.09.14.18.53.48 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 14 Sep 2026 18:53:49 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 16.0 \(3864.700.51.1.1\)) Subject: Re: Detaching a child table makes an expression using it unrestorable From: Jinqing Kuang In-Reply-To: Date: Tue, 15 Sep 2026 09:53:31 +0800 Cc: "pgsql-bugs@lists.postgresql.org" Content-Transfer-Encoding: quoted-printable Message-Id: <8E44C4A2-6184-473F-B536-F73F63AEF1D0@gmail.com> References: To: Heikki Linnakangas X-Mailer: Apple Mail (2.3864.700.51.1.1) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Sep 10, 2026, at 22:12, Heikki Linnakangas wrote: >=20 > I bumped into a sequence of commands that breaks pg_dump & restore: >=20 > ------------ > create table at_tab (a int, b int); > create table at_tab_child (a int, b int); > alter table at_tab_child inherit at_tab; >=20 > -- You can use the child's rowtype in the DEFAULT without a cast. > CREATE FUNCTION func_with_default( > arg at_tab DEFAULT ('(1, 2)'::at_tab_child) > ) RETURNS integer LANGUAGE plpgsql as $$ > begin > return arg.b; > end; > $$; >=20 > -- We allow detaching the child from the parent, despite the DEFAULT > -- expression. That is a not good, because if you try to recreate the > -- function, it's not accepted. I.e. pg_dump & restore is broken > alter table at_tab_child no inherit at_tab; > ------------ >=20 > The function still works after that. But if you run pg_dump (or do \ef = or something), the CREATE FUNCTION is deparsed as above, and when you = try to restore it you get an error: >=20 > ERROR: argument of DEFAULT must be type at_tab, not type at_tab_child > LINE 1: ...CTION public.func_with_default(arg at_tab DEFAULT = '(1,2)'::a... >=20 > You get the same effect with ATTACH/DETACH PARTITION instead of = INHERIT/NO INHERIT. >=20 > - Heikki >=20 Hi Heikki, I reproduced your example on 20-devel at 92aaf50e230. The function still works after NO INHERIT, but restoring the dump fails. I=E2=80=99d first try to preserve the current coercion rules: 1. Reject NO INHERIT/DETACH when it removes the last inheritance path needed by a stored ConvertRowtypeExpr, including indirect paths. 2. In pg_dump, make objects using these conversions depend on the required TABLE ATTACH entries, including intermediate partitions. This needs a way to find affected expressions in existing databases; recording dependencies only when creating new objects would miss them. It would also leave already-detached conversions needing repair. Alternatively, we could allow explicit casts between named composite types without inheritance if the source has matching names, types and typmods for all target fields, and deparse ConvertRowtypeExpr with that cast. Implicit coercions would still require inheritance. This would keep DETACH working, but would broaden the explicit-cast rules. Do you think that is preferable? The partition variant also fails to restore before any DETACH: CREATE TABLE p(a int, b int) PARTITION BY RANGE(a); CREATE TABLE c(a int, b int); ALTER TABLE p ATTACH PARTITION c FOR VALUES FROM (0) TO (10); CREATE FUNCTION f(arg p DEFAULT '(1,2)'::c) RETURNS integer LANGUAGE plpgsql AS $$BEGIN RETURN arg.b; END$$; -- pg_dump -s puts CREATE FUNCTION before ATTACH; restore fails. -- Moving ATTACH before CREATE FUNCTION makes restore succeed. Regards, Jinqing