Re: Domains vs data types

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Ertan Küçükoglu <ertan(dot)kucukoglu(at)gmail(dot)com>, pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: Domains vs data types
Date: 2025-08-20 15:05:44
Message-ID: 7cdd7a73-5a61-451b-9556-5cb523cfb239@aklaver.com
Views: Whole Thread | Raw Message | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 8/19/25 21:47, Ertan Küçükoglu wrote:
> Hello,
>
> I am using PostgreSQL 17.6.
> 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.
>
> For example I might have table defined as below
> create table test (
>   a integer,
>   b integer,
>   c integer,
>   d varchar(5)
> );
>
> I might also have ame table defined as below
>
> create domain aint integer;
> create domain s5 varchar(5);
>
> create table test_domain (
>   a aint,
>   b aint,
>   c aint,
>   d s5
> );
>
> Does the second table have any technical advantage/disadvantage over
> plain data type definition?
> Less metadata in memory? High metadata in memory? Less/increased disk space?

See:

https://www.postgresql.org/docs/current/catalog-pg-type.html

for what is stored in system catalog for a domain vs a base type.

Personally I don't see that integer --> aint really helps.
Also I am pretty sure varchar(5) --> s5 is still going to result in a
length check.

>
> Thanks & Regards,
> Ertan

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Adrian Klaver 2025-08-20 15:14:47 Re: Streaming replica hangs periodically for ~ 1 second - how to diagnose/debug
Previous Message Scot Kreienkamp 2025-08-20 14:59:17 RE: Streaming replica hangs periodically for ~ 1 second - how to diagnose/debug