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.94.2) (envelope-from ) id 1v9LnA-00GPIV-0V for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Oct 2025 11:05:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1v9Ln7-00Byyv-NM for pgsql-hackers@arkaria.postgresql.org; Thu, 16 Oct 2025 11:05:04 +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.94.2) (envelope-from ) id 1v9Ln7-00Byyh-CB for pgsql-hackers@lists.postgresql.org; Thu, 16 Oct 2025 11:05:04 +0000 Received: from mail-ua1-x92c.google.com ([2607:f8b0:4864:20::92c]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1v9Ln4-002Vna-0G for pgsql-hackers@postgresql.org; Thu, 16 Oct 2025 11:05:04 +0000 Received: by mail-ua1-x92c.google.com with SMTP id a1e0cc1a2514c-89019079fbeso119266241.2 for ; Thu, 16 Oct 2025 04:05:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1760612700; x=1761217500; darn=postgresql.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=qOzSzSkP+OfcpAWeco85jRuIxus4SHhb5XWhY8OSono=; b=lR0MJs1HxTeOp7FPCWgC8GT5/N/GStUcwcyz8I5/nx3GF3zm2RcAMc8dID3cJWq4bk b6HUquoYYD2hQqZx8OL3BEb89Er0OH4hkcsTI4PURSj+JN5v1ACogEFEe9VRUhR/3gNs V6flJgk/LCjGnZmAB1/1/lay0f05TB+p1xbh9elSpgWK1o1ItgHQpgQ88b1w8yNEK4Kz iU5/owRd+6DjzZZOcf5cUhn2MIDZQqCkHQTNavu/P4JcdqUitFAmb+7YjLDSsT9AmKuF 7onIXtMHQmGcA1MKw4eVxLtVv1H/6TvegRR+pl5pcskhw9VWWhExdmY7k50OoGvlgYcC UmiQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760612700; x=1761217500; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=qOzSzSkP+OfcpAWeco85jRuIxus4SHhb5XWhY8OSono=; b=rRueozXD1zg0GFaPp1z/3LVMnoUE6V6Gr06bBUtZ1NN7Wka6B3HY6x9Ckjf0MrcXHr /ZNmg+Djh3tpJopDE1YHikAuK6cJT/Ur8g/G/zjMlLaWL2jRcB+e5QrRlOV8/IbRS5dX nQhm1EfsplmMgVi8FU17oK+J9OJFSY1mQVSrqlTueScs9YMltnyWVXngMqEGWY+8XKWy xQZNdtlkll+Q4ZtXlgRY23wX8VK4lWCtyoSEv+moE51mGwQGnxSx05bcXTfad/X5/KcH LmurBBpYlqjylTqmb9MXJIKHEGH3K0SaspsqaNhriyd3YfkpBV+vFk8ZCExV+kWKS2hM 5rpg== X-Gm-Message-State: AOJu0YwSHPvK5A5S0DFNo8EMJYfahRAAcPbKEPnyl5FpPjF5Kbtbd3uz 7LvANffcMG8LoEQDX2o3ucIEDBtamEOpkBuCvEBNfADg+YFfyuDC3oPDfjL/WcicSlomDwSXiIO wkautwAVKaEjiMvQyo8h4iy2fPfunNNw= X-Gm-Gg: ASbGncvFO0q/j0dg3wDyLtJu4I4gepvdLf2k9EBOWI/zqTbFuYQ7x0NGCFNy26ACeBk Vro6K7TgpID4gWDWRVWanmKlUI6DZtNybGnnBXgZONZcQl0Bm4MhmOdbpV9OEdGdkVVBHIsCX98 uUCFXwTOX5N8uwNVcj+0cs6oRueRez8Q5/a4oXzODsXr01V2eN1UN454CTC4gSCU0QAy3SWTMuG +rTFUWaUk2fEuznVHEsuybVLT1ioatrXTfnN82g6nLUbFjLZLqOr4Y4S3LhBqgFnLEXMOck5p+u /Qa2qarp1XzvvJdWnHcOjYbZYyfl50vCpKWcylEYlWZj6HyeFnsnK4mGJHdUoGZbJBMfA4VjNFp CciXAZLxthVPJmxdPkZjzln8QMFca0uUfEltsRqdKOG2lST/BqLbs22xFuD7ny7gcFIylUdeDvf zePIhMpyBNhd4c X-Google-Smtp-Source: AGHT+IEAhHb/6h1cDuX/imUmiTdX51qeWyXK74YwS7sOQ1N2gAlLHgXzUL88X12Xcg/79J50NiNIFY1WjroFIsw6qi4= X-Received: by 2002:a05:6102:5690:b0:4c5:1c2e:79f5 with SMTP id ada2fe7eead31-5d5e2375a61mr11359139137.16.1760612700065; Thu, 16 Oct 2025 04:05:00 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: From: jian he Date: Thu, 16 Oct 2025 19:04:22 +0800 X-Gm-Features: AS18NWDeudJPI3Ojyu3UxRduffQ11J9K8SG0yLAqY4wzlcmWP1VGT5AOVTpG3ok Message-ID: Subject: Re: [PATCH] pg_get_domain_ddl: DDL reconstruction function for CREATE DOMAIN statement To: Tim Waizenegger Cc: pgsql-hackers@postgresql.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Thu, Oct 16, 2025 at 5:17=E2=80=AFPM Tim Waizenegger wrote: > > Hi all, > > Following the recent "Retail DDL" discussion [1], we're submitting anothe= r > implementation: pg_get_domain_ddl(). > > This function reconstructs CREATE DOMAIN statements for existing domains, > following what seems to be the agreed pg_get_{objecttype}_ddl naming conv= ention. > > ## Function > > pg_get_domain_ddl(regtype) returns text > > Returns a complete CREATE DOMAIN statement including base type, default v= alues, > and all constraints. Uses get_typdefault() for proper expression handling= and > supports schema-qualified domains. > + pg_get_domain_ddl + + pg_get_domain_ddl ( domain text ) + text + + + Reconstructs the creating command for a domain. + The result is a complete CREATE DOMAIN statemen= t. + text should be regtype + Oid domain_oid =3D PG_GETARG_OID(0); + HeapTuple typeTuple; ,.... + + /* Look up the domain in pg_type */ + typeTuple =3D SearchSysCache1(TYPEOID, ObjectIdGetDatum(domain_oid)); + select pg_get_domain_ddl(-1); will cause segfault. see https://www.postgresql.org/message-id/3759807.1711658868%40sss.pgh.pa.u= s and pg_get_trigger_ddl thread. NOT VALID check constraint handling is tricky currently. create domain x as int; alter domain x add constraint cc check(value > 2) not valid; select pg_get_domain_ddl('x'::regtype); CREATE DOMAIN public.x AS integer CONSTRAINT cc CHECK (VALUE > 2) NOT VALID= ; but putting the above to psql would result in syntax error. https://www.postgresql.org/docs/current/sql-createdomain.html [ COLLATE collation ] part not handled? create domain d0 as text collate "C"; select pg_get_domain_ddl('d0'::regtype); pg_get_domain_ddl ---------------------------------- CREATE DOMAIN public.d0 AS text; (1 row) we should expect CREATE DOMAIN public.d0 AS text COLLATE "C";