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 1up8hK-00HKbW-Iu for pgsql-general@arkaria.postgresql.org; Thu, 21 Aug 2025 17:03:35 +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 1up8hJ-000G0T-UI for pgsql-general@arkaria.postgresql.org; Thu, 21 Aug 2025 17:03:34 +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 1up8hJ-000G0J-In for pgsql-general@lists.postgresql.org; Thu, 21 Aug 2025 17:03:34 +0000 Received: from mail-lf1-x12a.google.com ([2a00:1450:4864:20::12a]) by magus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1up8hI-0017un-0b for pgsql-general@lists.postgresql.org; Thu, 21 Aug 2025 17:03:33 +0000 Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-55ce527ffbfso1125049e87.3 for ; Thu, 21 Aug 2025 10:03:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755795809; x=1756400609; darn=lists.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=RZ1nT6T1L3uNii0E10v0WbG+XnR9/cqsS6D//VTP3o0=; b=AAmjSQ2Dhr5dFtgOVjSjeJivZJVNARHBNipI47N0paDWUtt7zfudIDPtGFzXGUV5Nl vcoGotl4UgBFFs6+wy84MPY5rg6etxY/2vvv7vhAuFbr54rBkKPtznuE4Kkk07LoP/RS Ud1y1R1VIIgpSGgPqvQGeIY+CeEAClcdMWp6LFW0GuzBL+LRpZwdI5h6jvFuZrorU+bg rbQziHtNH1VI/oEhFAHRMkfxl3HUjR0VWyOFKC3JCw++luiMir9uBoh8kW+Lj0MIG5sS hTeMO4XM4c/GA3z5dHn8wjfij5HwqpaQWjoVKPefS21tlrOhUbGUBlV68huFWR1a21E9 iFhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755795809; x=1756400609; 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=RZ1nT6T1L3uNii0E10v0WbG+XnR9/cqsS6D//VTP3o0=; b=hToTYRcAOx+ftW9GootIeznRf7MXnbxD0Cy0Etkujt4SI7qHUCvmbEUETsXBV+2eP5 gJu8QjGRyHeoIqke/dVL80Xi4M5u2qxI68zs4CD8MjO3aMavkbZEB7L2uGUJiGwTsSQX XElbersmEtiyV5qQKhXYxxV/Wx4p33nNYgQdM+sT2uGCW1GZSr0eXCCUuX1HhK3g2Zdq 2t6b8whPFwmDr8B4+2e+MDdTB2u3aVFiBn7mtF8O6lhVPJK3mYpFVGz2HmRF/Lw/yRCN 2AkJuN+0UavgrxIfuhHkLn6y0bYvgZA9jnW189lus76Qe01K4Rkk2+XvkQPLn9tvZqjq 2Wxw== X-Forwarded-Encrypted: i=1; AJvYcCXAWA4sS+Y1pMUGFitEEaMToBGY+Qq2I6iPrCCbV3mxncavFY2PaT81plbF0bS4T4xHt46bCxoyml+8BNvR@lists.postgresql.org X-Gm-Message-State: AOJu0YySv3Cyz+FQEkMv97uLabKH2SdsykgeQCKBJmCcY1UdO5k6rOmL 7zplQZMyhp8xMVFDIP0wiWTQtgLS7RK07n1bhoBQYMGZwi9J8wWo1HatrDDlywgqwEzjhaES0jW E8kElmMpQmdbC2ZYhyAx/LSKueKLdD60= X-Gm-Gg: ASbGncvEcjEgT1Ifnjl1YSFP3MmeSdP49J10LjKwI6qh4p/h27iKD71xRlZ9dGCJ462 3/XsdJy5+lVzQY6AZkfke0RbNw1WUO9+fdNuvZgFjX/bjGYHHbQB7+p0Zuap07rNdhhGWOMKZji 5hc+Z94N8iNI46ongyZyNomagVK+ZOUv/pxSLdYDlxMW3IbjqWye08T57OW2oeKFmLVuCRjVTHx PiUWzZUyKBW9d49PIedsfRmtaswBMjKKZLCEu9s3g== X-Google-Smtp-Source: AGHT+IGLmnQrT6ENxuMGdKaXhxPi3o5dyfvrLQhssMsBOAh3rhjAxyB7ZiIAgRptnETDQGbFWQRtz5j30qSR2LTpQiM= X-Received: by 2002:ac2:51d2:0:b0:55b:8e3e:2be6 with SMTP id 2adb3069b0e04-55f0cd0c9e6mr62118e87.24.1755795808814; Thu, 21 Aug 2025 10:03:28 -0700 (PDT) MIME-Version: 1.0 References: <524E00FE-DBFF-483B-A276-467A0B979B1D@gmail.com> In-Reply-To: From: Merlin Moncure Date: Thu, 21 Aug 2025 11:03:17 -0600 X-Gm-Features: Ac12FXzUdSz7y0HYafPU_EIhT8c9tausv77k6C4huIaKQABy6wQzefsfl9fsaCQ Message-ID: Subject: Re: Domains vs data types To: Dominique Devienne Cc: Florents Tselai , =?UTF-8?B?RXJ0YW4gS8O8w6fDvGtvZ2x1?= , pgsql-general@lists.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, Aug 21, 2025 at 2:11=E2=80=AFAM Dominique Devienne wrote: > On Wed, Aug 20, 2025 at 7:37=E2=80=AFPM Florents Tselai > wrote: > > > On 20 Aug 2025, at 7:47=E2=80=AFAM, Ertan K=C3=BC=C3=A7=C3=BCkoglu wrote: > > > I would like to learn if there is any benefit of using domains over d= ata types for table column definitions in terms of performance gain/loss. > > > I know that this doesn=E2=80=99t answer your question, but before explo= ring custom types / domains, > > and based on experience, I=E2=80=99d strongly recommend exploring jsonb= instead as an alternative. > > I stayed out of that thread, but this makes me step out and react. > domains are typically out constraining the value space of a type. > I.e. a type with a CHECK constraint. W/o one, it's pretty useless IMHO. +1 this. The main use for domains is to allow for standard constraints. If you find yourself writing the same constraint over and over, that's when you might consider using them. For example, in the USA, vehicle identification numbers must be exactly 17 characters long. postgres@postgres=3D# create domain vin as text check (length(VALUE) =3D 17= ); CREATE DOMAIN postgres@postgres=3D# select 'abc'::TEXT::VIN; ERROR: value for domain vin violates check constraint "vin_check" The other use for domains I see is global sequences where you have many tables pulling from the same sequence. postgres@postgres=3D# create sequence global_id_seq; CREATE SEQUENCE postgres@postgres=3D# create domain global_id as bigint default nextval('global_id_seq'); CREATE DOMAIN Using domains is not really a performance thing, it's more regarding establishing rigor around type rules. In general, I tend not to use length constraints for tex columns anymore for most cases (just use text!), but I could get behind setting some standard length constraints, say, capped at 1k characters as a safety precaution. merlin merlin