Thread

  1. Domains on ranges should create a multirange

    Paul A Jungwirth <pj@illuminatedcomputing.com> — 2025-12-03T18:59:28Z

    Hi Hackers,
    
    While reviewing
    https://www.postgresql.org/message-id/CACJufxGoAmN_0iJ%3DhjTG0vGpOSOyy-vYyfE%2B-q0AWxrq2_p5XQ%40mail.gmail.com,
    I noticed that when you create a domain on a rangetype, you don't get
    a corresponding multirange. For instance:
    
    ```
    [v19devel:5432][481380] mr=# create domain int4range_d as int4range
    check (value <> '[4,5)');
    CREATE DOMAIN
    [v19devel:5432][481380] mr=# select oid, typname, typtype, typbasetype
    from pg_type where oid >= 20000;
      oid  |   typname    | typtype | typbasetype
    -------+--------------+---------+-------------
     24694 | _int4range_d | b       |           0
     24695 | int4range_d  | d       |        3904
    (2 rows)
    ```
    
    This means there is no way to get a multirange over a domain'ed rangetype.
    
    On the other hand you *can* get a multirange over a rangetype whose
    subtype has a domain:
    
    ```
    [v19devel:5432][481380] mr=# select oid, typname, typtype, typbasetype
    from pg_type where oid > 24695;
      oid  |      typname       | typtype | typbasetype
    -------+--------------------+---------+-------------
     24697 | _integer_d         | b       |           0
     24698 | integer_d          | d       |          23
     24700 | _int4_d_range      | b       |           0
     24701 | int4_d_multirange  | m       |           0
     24702 | _int4_d_multirange | b       |           0
     24703 | int4_d_range       | r       |           0
    (6 rows)
    ```
    
    This feels like a bug. Are there any backwards compatibility concerns,
    if I write a patch to create a multirange when a domain over a range
    is created?
    
    Yours,
    
    -- 
    Paul              ~{:-)
    pj@illuminatedcomputing.com