unnest multirange, returned order

From: PG Doc comments form <noreply(at)postgresql(dot)org>
To: pgsql-docs(at)lists(dot)postgresql(dot)org
Cc: daniel(dot)fredouille(at)gmail(dot)com
Subject: unnest multirange, returned order
Date: 2023-10-02 18:42:14
Message-ID: 169627213477.3727338.17653654241633692682@wrigleys.postgresql.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-docs pgsql-hackers

The following documentation comment has been logged on the website:

Page: https://www.postgresql.org/docs/16/functions-range.html
Description:

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".

Some context: I ask because we have some seemingly random (and impossible to
repro in tests up to now) errors in our code. The code assumes that this
returns things in range order and as the doc is unclear to me on this point,
I cannot exclude this to be our culprit.

Thank you

Responses

Browse pgsql-docs by date

  From Date Subject
Next Message Laurenz Albe 2023-10-03 13:46:23 Re: unnest multirange, returned order
Previous Message Giampaolo Capelli 2023-10-02 15:22:18 Re: examples for windows functions

Browse pgsql-hackers by date

  From Date Subject
Next Message Robert Haas 2023-10-02 18:55:15 Re: [DOCS] HOT - correct claim about indexes not referencing old line pointers
Previous Message Peter Eisentraut 2023-10-02 18:27:00 Commitfest 2023-09 has finished