pg.ddx.io  pgsql-docs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: daniel.fredouille@gmail.com
To: pgsql-docs@lists.postgresql.org
Subject: Re: unnest multirange, returned order
Date: Tue, 03 Oct 2023 15:46:23 +0200
Message-ID: <2bad53942920d2e501661af4cd49d6644a22b801.camel@cybertec.at> (raw)
In-Reply-To: <169627213477.3727338.17653654241633692682@wrigleys.postgresql.org>
References: <169627213477.3727338.17653654241633692682@wrigleys.postgresql.org>

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





view thread (11+ messages)  latest in thread

Message-ID: <2bad53942920d2e501661af4cd49d6644a22b801.camel@cybertec.at>
Permalink:  ../2bad53942920d2e501661af4cd49d6644a22b801.camel@cybertec.at/
Also on:    postgresql.org/message-id/2bad53942920d2e501661af4cd49d6644a22b801.camel@cybertec.at

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-docs@postgresql.org
  Cc: laurenz.albe@cybertec.at, daniel.fredouille@gmail.com, pgsql-docs@lists.postgresql.org
  Subject: Re: unnest multirange, returned order
  In-Reply-To: <2bad53942920d2e501661af4cd49d6644a22b801.camel@cybertec.at>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox