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 1wZEUo-000sO7-1H for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Jun 2026 21:05:26 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.96) (envelope-from ) id 1wZEUm-00DVkO-33 for pgsql-hackers@arkaria.postgresql.org; Mon, 15 Jun 2026 21:05:24 +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 1wZEUm-00DVkF-1b for pgsql-hackers@lists.postgresql.org; Mon, 15 Jun 2026 21:05:24 +0000 Received: from mail-lf1-x133.google.com ([2a00:1450:4864:20::133]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.98.2) (envelope-from ) id 1wZEUj-00000000ara-3ERx for pgsql-hackers@lists.postgresql.org; Mon, 15 Jun 2026 21:05:23 +0000 Received: by mail-lf1-x133.google.com with SMTP id 2adb3069b0e04-5aa68dbb38aso3411309e87.2 for ; Mon, 15 Jun 2026 14:05:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1781557519; cv=none; d=google.com; s=arc-20240605; b=hgWEF0XwzOTvFod3FK20SI832mz+zJ5ktJfg0oU3CTywoqgwa+Dxbw61NluBMMZ9hP q/rSnLXnMwibZAyZA6/LNaZtaG82Bk3uX5RaIpMUJWo6DWvnEp1NVqy3dmHPzpySGkwK 9jB7y3fURMRpwh8tpOppS0M75Zw5tc6U/dHsu7W330j77xlTQc0jx2Vpk9gdxEoNXImO KXwM6ZHwF+UpCRbVI7gfluiq0fNQXbg08ftA52v+rQKdyDYGOqZOqGTLQL7dyIWyp2yz 1G8n4as/AZ/bqvbfbSzxr0Z9GnF14f8yFjTK3kmQRXLRRV7ofmUncr+rEPX2NxnDVVwv sEpw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:dkim-signature; bh=A/8GIu9UgK43RUEnwomfq/MrZ9RLOi1Iq++aeEXDqq4=; fh=4eIrTeqEcg16HyjLRqyT1pC3S7V1/TiTt4pVL5i58Bg=; b=asLPImWzn0aonaatqrTTcH7L2DUVvvcwL7M9JvhKJBwX85sJPYyoUkUPDe6amQD2LC IAR+UEY2bfURExQCZRGZMzwlJsb6zfKDdwwJ92Fa50JHpC6XgYFhCkFO2mPicAGDIMjt d4rEM7UxILB28ALcSBoXYnpulSdRwvJIGcZq3phyxuduJWg/Pct/gFJQT6qcjKKLdxyG qWN7ndHuAZLLEfB/IXXvt9/U7f/HhDQ12PZJXoCJrr4N88k5hzfA3aOAOQqmzyWNaTSm kbV5Tp4CsUgDijCgSCtzucUQN+QQmg5/Iihoz0cqndwtfZtRas1pmm35T8Co+8bMwdZS zCTg==; 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=f10-com-br.20251104.gappssmtp.com; s=20251104; t=1781557519; x=1782162319; darn=lists.postgresql.org; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=A/8GIu9UgK43RUEnwomfq/MrZ9RLOi1Iq++aeEXDqq4=; b=x3x1yN1qqGf9hwI4XQ7sdYBHjq9UBU4Chkz0spAkUHCJzFCl8agwjFj6yJDleo/mD8 vCuy9jnL0hNLamOduVdVH9DPgWaB60e0XWw2AWvGxI0TL9wUyJFPG8j5pP3VE1johie/ x4BQNw5SdbqBSFuXZbuhRXb8KvJ4FthpyBKAm8OsQ3qY23r/j/0xPLtQWZfaBYQ9umH/ uxQm5hyOQ79VJcVLFj8sEXVNylITVCXijacxwKqMmymZ/IbyaarBGcWptDpZMFuvyEau 4tfHKwGuoSSmpgm5iygAbEdOXp8ko8zQOfbQ+bTuqyBUF0ilPeWWA29uV2jfTO14JjDg 02JA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1781557519; x=1782162319; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=A/8GIu9UgK43RUEnwomfq/MrZ9RLOi1Iq++aeEXDqq4=; b=NHFaBEr6OtOE7D3jv3k6kufkHXuMCnoFmzBYuinRYXB7Y/p25xCVkddDN2F5j1Ho/3 wpfYU4qKDQ7g7O7GofGBC/g73VbprnxKeDExxCwXY6ltvkZQfXNZdZkcCP73YdkrIzOB Ic6yXm9woNg8k271VKYktWgJwSrL9eD4Xeps7RKoDGV2EvJUVVp+ONXlXmXBuzu6cqzB uZB05ZNXkE8fhv/9MrcQehV55FnmdVYUfO/Qga85vA7DzoARWtAXlvIdO9yT59p1pZm8 Xhe0kz1r45dADNQmnOJaAAZ4GaQkc/I0PDjxDF0jsECwtbCqn7435bMsQuvWHpP1U7p+ hgiw== X-Forwarded-Encrypted: i=1; AFNElJ+pKHC2XlS092mX/53AwltH654UJDStOqg7Y7MLc+rKltPoJmJVO3wBrOD1cU1jJQNRcndXvYo8LTKa0cVA@lists.postgresql.org X-Gm-Message-State: AOJu0YxP4MghLWkwkM08/b0WbAK5530sKXpUpZhN/cPX8GEqm6g4Pnz2 mKACqss+vISHIRBsev5F9GihNb7Wq7dvkgIpc5+g5ksoQK4894LSiMHfK/X5qAMmQxYf5m/NInI Ygvxz6Fb5RU9lG+tOz7zuMM/7M0WlIApb/VwXCCGU X-Gm-Gg: Acq92OFvHKSW2aQ26BBbI6KRuqRztBY1FvfG6/IKdwYxi0LGwtT37mFN4NJ4NLzLWBn c0XGpk6pzK8RHmzUTPfjNUYWWPsqENcIXtPsvuLMdrzt6eWR+j87rITuzbAp2+5FNTqbDn4IqIO D0PC1GW5HMa4/4HYLT4OHbU4Y9POJBdRZFyANxWVFVvZVxGnQvEtzIMARIGcTBG8ssBfND1r5X0 c1JTPKjfbIlnwWT2nKepXvfszTtIa/U5SLcoZrlP0Z+tiGiBGFhPwWF5/0wOm7recKo45kyMK2S rlQd4Q== X-Received: by 2002:a05:6512:144a:20b0:5a8:f6fd:f48d with SMTP id 2adb3069b0e04-5ad437552abmr159101e87.40.1781557519347; Mon, 15 Jun 2026 14:05:19 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: Marcos Pegoraro Date: Mon, 15 Jun 2026 18:04:43 -0300 X-Gm-Features: AVVi8Cfxi090egO8k0igBavmk2MnBmekrnDDmY_suAGcul4m9gEm9_6uraG4p_g Message-ID: Subject: Re: [PATCH] Add pg_get_table_ddl() to reconstruct CREATE TABLE statements To: Akshay Joshi Cc: Zsolt Parragi , pgsql-hackers@lists.postgresql.org Content-Type: multipart/alternative; boundary="000000000000167bda0654512fd1" List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --000000000000167bda0654512fd1 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Em seg., 15 de jun. de 2026 =C3=A0s 04:52, Akshay Joshi < akshay.joshi@enterprisedb.com> escreveu: > I don't think per-contype flags are the right shape, though. The existing > toggles group by catalog (indexes, constraints, rules, ...); splitting > constraints into PK/FK/CHECK/UNIQUE/EXCLUDE/NOT NULL adds six flags on a > second axis, and the function already carries nine. Only FKs have the > cross-table dependency-ordering problem; the rest only reference the same > table, so splitting them unlocks nothing new. > Ok, I understand your point. Initially, I saw the usefulness of this function for cloning a schema, something very common in a multi-tenant model. But creating the foreign keys along with the create table makes that unfeasible. Options are variadic, so you could split your emit_local_constraints into +emit_local_foreign_keys_constraints(TableDdlContext * ctx) + if (!(ctx->include_constraints || ctx->include_foreign_keys)) then + return +emit_local_primary_keys_constraints(TableDdlContext * ctx) + if (!(ctx->include_constraints || ctx->include_primary_keys)) then + return pg_get_table_ddl('x','includes_constraints','true') -- would print all constraints pg_get_table_ddl('x','include_primary_keys','true') -- would print only primary key constraints regards Marcos --000000000000167bda0654512fd1 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
<= span style=3D"font-family:Arial,Helvetica,sans-serif;color:rgb(34,34,34)">E= m seg., 15 de jun. de 2026 =C3=A0s 04:52, Akshay Joshi <akshay.joshi@enterprised= b.com> escreveu:
=
I don't think per-contype flags are= the right shape, though. The existing toggles group by catalog (indexes, c= onstraints, rules, ...); splitting constraints into PK/FK/CHECK/UNIQUE/EXCL= UDE/NOT NULL adds six flags on a second axis, and the function already carr= ies nine. Only FKs have the cross-table dependency-ordering problem; the re= st only reference the same table, so splitting them unlocks nothing new.

Ok, I understa= nd your point. Initially, I saw the usefulness of this function for cloning= a schema, something very common in a multi-tenant model. But creating the = foreign keys along with the create table makes that unfeasible.

Options are variadic, so you could = split your=C2=A0emit_local_constraints into=C2=A0
+e= mit_local_foreign_keys_constraints(TableDdlContext * ctx)=C2=A0
+ if (!(ctx->include_constraints || ctx->include_for= eign_keys)) then
+=C2=A0 =C2=A0return

+emit_local_primary_keys_constraints(TableDdlCont= ext * ctx)=C2=A0
+ if (!(ctx-&= gt;include_constraints || ctx->include_primary_keys)) then
+= =C2=A0 =C2=A0return

pg_get_table_ddl('x','includes_constraints','tr= ue') -- would print all constraints
pg_get_table= _ddl('x','include_primary_keys','true') -- would pr= int only primary key constraints

regards
Marcos
--000000000000167bda0654512fd1--