Re: unnest multirange, returned order

From: Daniel Fredouille <daniel(dot)fredouille(at)gmail(dot)com>
To: Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at>
Cc: pgsql-docs(at)lists(dot)postgresql(dot)org
Subject: Re: unnest multirange, returned order
Date: 2023-10-04 00:40:40
Message-ID: CAEpV6kX9PJAuQ_=5c7ZxCSASu76hkvGfVvwU6WkHTRXzApknfQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-hackers

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

Right, I believe that you are right but then this information is not useful
for the developer.
If storage order is always ascending by range order then let's make it
clear, if order cannot be counted upon as it may evolve from postgres
version to version, then let's make it clear as well. WDYT ?

Thank you.
Daniel Fredouille

Le mar. 3 oct. 2023 à 09:46, Laurenz Albe <laurenz(dot)albe(at)cybertec(dot)at> a
écrit :

> 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 Laurenz Albe 2023-10-04 07:20:16 Re: unnest multirange, returned order
Previous Message Tom Lane 2023-10-03 22:44:37 Re: Corresponding documentation page does not mention about `spread` mode

Browse pgsql-hackers by date

  From Date Subject
Next Message David Rowley 2023-10-04 00:41:24 Re: make add_paths_to_append_rel aware of startup cost
Previous Message Alexander Korotkov 2023-10-04 00:12:02 Re: Removing unneeded self joins