Re: unnest multirange, returned order

From: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
To: daniel(dot)fredouille(at)gmail(dot)com, pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: unnest multirange, returned order
Date: 2023-10-03 13:46:23
Message-ID: 2bad53942920d2e501661af4cd49d6644a22b801.camel@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-hackers

On Mon, 2023-10-02 at 18:42 +0000, PG Doc comments form wrote:
> Page: https://www.postgresql.org/docs/16/functions-range.html
>
> The doc says:
> * unnest ( anymultirange ) → setof anyrange
> * Expands a multirange into a set of ranges. The ranges are read out in
> storage order (ascending).
>
> What is storage order ?
>
> At first I thought that it was the order in which the different ranges are
> inserted in the internal data structure. However, the following sort of
> shows that it is not:
> ```
> postgres=# select unnest('{[1,4), [8,10)}'::int4multirange + '{[-5,-3)}' -
> '{[2,3)}') ;
>  unnest
> ---------
>  [-5,-3)
>  [1,2)
>  [3,4)
>  [8,10)
> (4 lignes)
> ```
> Whatever I try, it always return in range order instead of "storage order".

I'd say that the storag order is the order in which PostgreSQL stores
multiranges internally:

SELECT '{[100,200),[-100,-50),[-1,2)}'::int4multirange;

int4multirange
═══════════════════════════════
{[-100,-50),[-1,2),[100,200)}
(1 row)

Yours,
Laurenz Albe

In response to

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message PG Doc comments form 2023-10-03 19:00:49 INT4RANGE Upper bound always includes a higher number
Previous Message PG Doc comments form 2023-10-02 18:42:14 unnest multirange, returned order

Browse pgsql-hackers by date

  From Date Subject
Next Message David G. Johnston 2023-10-03 13:53:35 Re: CHECK Constraint Deferrable
Previous Message Daniel Gustafsson 2023-10-03 13:43:38 Re: On login trigger: take three