public inbox for [email protected]
help / color / mirror / Atom feedFrom: Merlin Moncure <[email protected]>
To: Dominique Devienne <[email protected]>
Cc: Florents Tselai <[email protected]>
Cc: Ertan Küçükoglu <[email protected]>
Cc: [email protected]
Subject: Re: Domains vs data types
Date: Thu, 21 Aug 2025 11:03:17 -0600
Message-ID: <CAHyXU0wHFNY=N8T4pdWFMpBiKeZmCYjr4cmF7ycxE0o_Ozp1QQ@mail.gmail.com> (raw)
In-Reply-To: <CAFCRh-9n3Hf+D0fNKX4UQ34WxFSCz+SUUiB8T5EGyj9206yCMQ@mail.gmail.com>
References: <CAH2i4yf_M5NfX_kDu6_2Z+sgqLOZK9vCsF3EfmwZQyYFuAMxpg@mail.gmail.com>
<[email protected]>
<CAFCRh-9n3Hf+D0fNKX4UQ34WxFSCz+SUUiB8T5EGyj9206yCMQ@mail.gmail.com>
On Thu, Aug 21, 2025 at 2:11 AM Dominique Devienne <[email protected]> wrote:
> On Wed, Aug 20, 2025 at 7:37 PM Florents Tselai
> <[email protected]> wrote:
> > > On 20 Aug 2025, at 7:47 AM, Ertan Küçükoglu <[email protected]> wrote:
> > > I would like to learn if there is any benefit of using domains over data types for table column definitions in terms of performance gain/loss.
>
> > I know that this doesn’t answer your question, but before exploring custom types / domains,
> > and based on experience, I’d 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=# create domain vin as text check (length(VALUE) = 17);
CREATE DOMAIN
postgres@postgres=# 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=# create sequence global_id_seq;
CREATE SEQUENCE
postgres@postgres=# 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
view thread (3+ messages)
reply
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected], [email protected], [email protected], [email protected]
Subject: Re: Domains vs data types
In-Reply-To: <CAHyXU0wHFNY=N8T4pdWFMpBiKeZmCYjr4cmF7ycxE0o_Ozp1QQ@mail.gmail.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox