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 1up0OK-00EVuH-CI for pgsql-general@arkaria.postgresql.org; Thu, 21 Aug 2025 08:11:25 +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 1up0OI-00F2VI-C0 for pgsql-general@arkaria.postgresql.org; Thu, 21 Aug 2025 08:11:22 +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.94.2) (envelope-from ) id 1up0OH-00F2V9-Vt for pgsql-general@lists.postgresql.org; Thu, 21 Aug 2025 08:11:22 +0000 Received: from mail-oo1-xc36.google.com ([2607:f8b0:4864:20::c36]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.96) (envelope-from ) id 1up0OG-000zAs-0K for pgsql-general@lists.postgresql.org; Thu, 21 Aug 2025 08:11:21 +0000 Received: by mail-oo1-xc36.google.com with SMTP id 006d021491bc7-61bf9ef4cc0so387528eaf.0 for ; Thu, 21 Aug 2025 01:11:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1755763880; x=1756368680; 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=qYBTh0AvpxEippWbMF1pSNwRsKuhXI0FWaXYV4wtdDA=; b=FE1aKhZlaTN088tNVCtXA+eKT76aus6Bv+jM7cqqIRsr2F7hS3ggvOPfoRI26EmpQq YBXzmt6oqpoazOcGfAmRoyAvf8ElcCqYWOdBZ/ilkqsn9jGRlTli9pWjjX6qtX3xxmq1 8F0rYnjTHFBET86WnMgSwlyKHTyf1a9EgUQpYSVSbJMiJPFE0tDzpta+5wC9CNIQCb1I seiPa39Z90TeqKrRc7PyyV5coSai53nXK099FVLVuM+VFPQDoDy+0qS0opTMpEB/cRa9 IrA/27g4Yvr/QwOzOpDsjsxvbA1O9ThtC6t1A7xAL+944h7mlGxlJ4Z42vg8+CtVAl9D g84g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1755763880; x=1756368680; 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=qYBTh0AvpxEippWbMF1pSNwRsKuhXI0FWaXYV4wtdDA=; b=bDnpyBVLjn+TePmdUAeWxABEwQlHDURL2ddYpv5kwyoxrqwza3yWpDIZy/UFioVuj3 gy0T0H0ESliDtS0dAjWsQQ3mwGoy6hDuiGPoH9LKBH9f0joPHWAfidv7Kq1yFzSSogBv VvYiJrGjJUMSO/pmlxqVMaTj9diuWvutUA9OGRTjmi3pC63vZUFbAiDYEfVYzTuFFwDu BvG3v/PbOFzBvd6HHIcB7qDBABNGTPe847vA0KjaPXOSRYJrSnCov1oIkFbPB/2rE/aB bP4SBinfIXu7hNwPb6TGAwnArhBP5FOr++o/Xsg885t0TdwWbAyV1R1NZhOPi4ojSEXz KcLw== X-Forwarded-Encrypted: i=1; AJvYcCUdQDhpX1dO/Azy8rnxe+1/wTGqaCt9BqFwbAwI0TEgnG00Bux6InoM/Lsp4iDAKyj+WYb/fpKYb4tDLIJT@lists.postgresql.org X-Gm-Message-State: AOJu0Yz08BGleKANuQlKaL5ljyFMih4BJIfaLk08a/5YvnbjcmNcaV/2 Pb1+tC4ZkQAuMy3DURwYLeOA5ocib2UfwPTltoqhXHIXZ6GKM46Q1VtpeelUE5v/fcpZ+0jrx2l TFjJ83hL8EPSCa6UVUcgXavQgyKZdN78= X-Gm-Gg: ASbGnctEB90Oj9IsOal9VGjS4N6ua3K4l7hy9arr34dzouFxv/VLbSko8yEGe4Eh5Nl ZdgzdUD6eZys+m/f0RulQ54cJenRfrwM5bEG3IFUsV6Blk9WssHw24ICsXVD+xgef6SvKh5hdlr ucrTh/20k+dbH2KsumiNyuVuYHqMQ0xCrbNeVdZ3szEbn2g85+H1QmN1+DLSyI6ywlT4USHyvUe 30vb+OHgw== X-Google-Smtp-Source: AGHT+IFFiVZsFPTjVwEinq6MbguvbcSrhdZtgGLmz7s7TWzDXqGLVoTy5LxVmxjohSamNbiXohd6HuO+bUZvyrAQ3EU= X-Received: by 2002:a05:6808:1311:b0:41b:44b6:c823 with SMTP id 5614622812f47-4377d7d0b2emr556760b6e.33.1755763879884; Thu, 21 Aug 2025 01:11:19 -0700 (PDT) MIME-Version: 1.0 References: <524E00FE-DBFF-483B-A276-467A0B979B1D@gmail.com> In-Reply-To: <524E00FE-DBFF-483B-A276-467A0B979B1D@gmail.com> From: Dominique Devienne Date: Thu, 21 Aug 2025 10:11:08 +0200 X-Gm-Features: Ac12FXyAZXdZpdf5N97-S_DsWrV2TtB5FPR6IbRfjE5G4XD7K_6CRoqkywaNx-k Message-ID: Subject: Re: Domains vs data types To: Florents Tselai Cc: =?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 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 dat= a types for table column definitions in terms of performance gain/loss. > I know that this doesn=E2=80=99t answer your question, but before explori= ng custom types / domains, > and based on experience, I=E2=80=99d strongly recommend exploring jsonb i= nstead 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. While json/jsonb is about denormalizing and stuffing unconstrained data, of arbitrary (and often evolving) content. No need for complex relational modeling and its associated constraints and "rigidity". I.e. easy evolution of the data tier, at the cost of applications having to deal with the compl= exity themselves of constrained data (must expect anything). Your SQL also become= s less expressive or more complex, although PostgreSQL has excellent JSON sup= port. > Also note that using custom types can lead to some confusion initially fo= r basic stuff > you can=E2=80=99t do things like SELECT mytype.f1 and instead you have to= do (mytype).f1 I guess you're talking about composite types? Not sure OP had that in mind. But that's still a good point. Thanks for sharing. Yes, using a custom type/domain is more metadata, since a new row in pg_typ= e. But that's mostly negligeable. There's always an (integral) OID associated to columns, so only its value changes if you start using a custom type, be it i memory or on disk. So no, using a custom type is unlikely to make things bigger or slower. That said, in my case, because I use the BINARY mode of LIBPQ and COPY, it does matter, as my code knows about built-in OIDs, but not of custom OID= s for custom types. But few people care about such things. FWIW, --DD