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 1waf9V-001xsK-2e for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jun 2026 19:45:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1waf9S-0008eF-2j for pgsql-hackers@arkaria.postgresql.org; Fri, 19 Jun 2026 19:45:18 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1waf9S-0008e5-1e for pgsql-hackers@lists.postgresql.org; Fri, 19 Jun 2026 19:45:18 +0000 Received: from mail-yw1-x1132.google.com ([2607:f8b0:4864:20::1132]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1waf9P-00000001Js7-1VFN for pgsql-hackers@lists.postgresql.org; Fri, 19 Jun 2026 19:45:17 +0000 Received: by mail-yw1-x1132.google.com with SMTP id 00721157ae682-7ff0584c6b5so36864867b3.2 for ; Fri, 19 Jun 2026 12:45:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781898313; cv=none; d=google.com; s=arc-20240605; b=H8hFIg2PTof5Cpxsm52WPvEqpltdFlV/fwaeLd8KvpPiOag95U0Hr/KT9h6bvt7SYf o5rEv4Z7/tb+XlxnkXxbB/pEocmdo+JMdnOyX+7PJr5AptVsEnAEn9zdSP7+wLN/ehnu G22Xcv/jH2NTvfC16oJ/+DMgUX2wY39BXO5e2vxAO5N2hfvcNIRS4tht8SN2LCWIphvz 8IxqfJDf4bgoLt5FamCNzge8ikdY3Z8lvfgePOWEK2Zq/cCM5irqh8x/Za0NY8LOTSo3 waSjeeccEAVe13RVKFb68J6T9lBqfqWu/xjP3LcCmGjALFy2hoArLE+eFal6ZMOoitJS W8RQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :dkim-signature; bh=o809qO/P4LzIcAbEw/un/a+A2zVhW17imSNvFTnscao=; fh=nwNxTtLLPTU0ewfLM7SSbrjMajMl+wwnFkCY/fi90vE=; b=QjK7TQE3ijHw/M2WUN2qwuR35Dvn91bAQXsty7hnozI0pKuiAE3EXmDqj2ehgLBNvo umkGFRrZ11TopSprdrdsu/fl2FA/53+3DG1vhKS6TQ5w+rhENb4FMQLas/W9U7tB7dih gnpAqhLDyOCXBEVPz/NE2+S2QFUkvT6XbC6i820kVn5yqloc8vySG1O8Psa49sVNRcEt 124vblPhz9DeLwD0PjecBsjtyQjQ5C7g5jw8+Spwvt2VPfhjvziO3OlRe0cv3Rq/oFJG C85xvSO7pH7LTFQFWDh99VJMN4dobwM9f8j98xq4uzrNDUDeiBDT56zZtRwC8G6xTf6i SAig==; darn=lists.postgresql.org ARC-Authentication-Results: i=1; mx.google.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=percona.com; s=google; t=1781898313; x=1782503113; darn=lists.postgresql.org; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :from:to:cc:subject:date:message-id:reply-to; bh=o809qO/P4LzIcAbEw/un/a+A2zVhW17imSNvFTnscao=; b=al1bKhrj3fV2jcIjuGRb/mGcLss33/Y/SvACncxTdLrX5z1FBB6GDIWPW3EAEnEXkB t1D3ln4AHYH2V34fPp5eo3WFZ9x7wUoWrKSkQP2yRKzG0GEN61OCs8p3WzQDiI0sIp5U YpTJkJIdh4/1gNclT3qNCjDjOCayNce/o8e5KBZRba3EKoWSfHxdgoVFFEnoC0PW495a 9HVMUGbxhZv3Kn2fFYGrkwvTCNeOOXil0SWL3+P4CXx4a8w0oGBt0BlJbUNvhzT5Ho/3 ZjYTbVE2AgCnxXURPXRgk/jc8YGCm48ck/Fw6QnBLbPoI4vPaqnxOGYFzEHdGxpxxU19 ecxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781898313; x=1782503113; h=to:subject:message-id:date:mime-version:references:in-reply-to:from :x-gm-gg:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=o809qO/P4LzIcAbEw/un/a+A2zVhW17imSNvFTnscao=; b=EjsuZmjKIy5S82AercNvDnNMlld4GUsZ+xaaLQ2qnKAoib4ApspGDwdKXcUiu5SLTl p/sDpFgBo03tFu40mZFSSNyICjk6ViLNkRecy/X42zQ9BgtEHndIr5RyOVyRys+fX3nI VtG1pKHJlWJYrdl6tpkUFEcC8a2xKM5aLtuHXhHeXYBAR4XjRL9Wzzq72ceKTFJ9M7sb l4MAv5yObbW8aK97hGHltPdNd4RvWU2nXVSMdjNDjvnc/0z76y8s5E++g3Mzqnk7aPJT JkSOJ8yftLqY9VRAXEV/+w0U6+ATKeGnjEP+8sXkqOcBDDFf2eO+1ZuYrLiMiZqGwU8v PLOA== X-Gm-Message-State: AOJu0YwKQniQUYCBL6LgZv1lf3OYhsrA981JwmnHWs5plpAJbVGkRPsE iSWrkXmHwZQlBRTKxx4XduSXTFs1hr0rEcz4TnzgY4LBZJQ11gQjvihOJGgpzBVmMNwqaGQglmt WsD9tsMrB7o0Urm/ebmcz7D9ShNjbEV42+RokeelbtdkFg+V82zPSAqz4IPQ8RNU2uEwpg59cH1 1Nu2hv113VpJN0Wr7koCMNMY1YRIRnseOru5uvJaKUtdCpyck2b9OP4ewTOyb9BGf5rSk9gImWT YKDgxACHaG6PF3xI+Y84ALPIoFy82sU0EOTzlr43AoHIRlHCVl36n8ArrbmhjZJszsjAmTTWvWt ew== X-Gm-Gg: AfdE7cki0z0AFxB6f8RRfvBirFxvUuVo/hJBmWoovSYzmFQWmDxiCs2PuHwpscsYXx+ VOkQDBIiP9vd5+LO9ZTpVDJD2/P6YPRXA9ivPgECz1hAmgUopKELPfy8v6PttYhCq2EYkAHDJAD 65eL2N+06KoEwZnn5hhqDUgTUSHYOAYE7S5uAE7nVeHabWzQxytkfWlb3vTiu4flyzzOclLtZw3 bZ/rnsE69ZOV2GUk1o2w6+0bCOe2Wic9VjkZTdv2jkeGOnzHaWNj53EnBiVfJAB49fyYJ+zJczO NsxEJyfkCcTKhjQ8quGNaAGaFVQir/dlB/Z3UgYKyZdA2UzFklI0gDmhoQ== X-Received: by 2002:a05:690c:9690:b0:7fd:67e8:d75d with SMTP id 00721157ae682-8013237019bmr57382447b3.22.1781898312904; Fri, 19 Jun 2026 12:45:12 -0700 (PDT) Received: from 298783833264 named unknown by gmailapi.google.com with HTTPREST; Fri, 19 Jun 2026 14:45:12 -0500 Received: from 298783833264 named unknown by gmailapi.google.com with HTTPREST; Fri, 19 Jun 2026 14:45:12 -0500 From: Zsolt Parragi In-Reply-To: References: MIME-Version: 1.0 Date: Fri, 19 Jun 2026 14:45:12 -0500 X-Gm-Features: AVVi8CcdVyTZajZRmNnP506GSca-yYANahaL34kbl75OQLyiquUO0nQAsOLGO7g Message-ID: Subject: Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements To: pgsql-hackers@lists.postgresql.org Content-Type: text/plain; charset="UTF-8" X-CLOUD-SEC-AV-Sent: true X-CLOUD-SEC-AV-Info: percona,google_mail,monitor X-Gm-Spam: 0 X-Gm-Phishy: 0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk The previous features all look good to me, I only have one question for the new flag. > Calling > pg_get_table_ddl(t, 'includes_foreign_keys', 'false') now emits everything > except FOREIGN KEY constraints. This covers the multi-tenant clone > workflow: create tables first without cross-table references, then re-run > with the default to add the constraints once all targets exist. I think this feature needs a bit more documentation, an "only_foreign_keys" flag, or both. CREATE TABLE refd (id int PRIMARY KEY); CREATE TABLE cons (a int CHECK(a>0), b int UNIQUE, c int REFERENCES refd(id)); -- pass 1: running without foreign keys SELECT * FROM pg_get_table_ddl('cons','includes_foreign_keys','false'); -- execute everything -- loading data -- pass 2: running with everything SELECT * FROM pg_get_table_ddl('cons','includes_foreign_keys','true'); -- ERROR: relation "cons" already exists (and the unique constraint also collides) I could do a "grep FOREIGN KEY" before executing (unless it's a tricky schema where that phrase appears elsewhere), or since psql continues on error, it will simply work if I accept a significant error noise, but then the documentation should be clear about this limitation. Following the documented approach and getting a bunch of unexpected errors could be confusing for users.