Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnfjK-00BbRL-HX for pgsql-docs@arkaria.postgresql.org; Tue, 03 Oct 2023 13:46:30 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1qnfjJ-005wLS-0v for pgsql-docs@arkaria.postgresql.org; Tue, 03 Oct 2023 13:46:29 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1qnfjI-005wKq-Oa for pgsql-docs@lists.postgresql.org; Tue, 03 Oct 2023 13:46:28 +0000 Received: from mail-wr1-x42d.google.com ([2a00:1450:4864:20::42d]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1qnfjG-007zGN-E1 for pgsql-docs@lists.postgresql.org; Tue, 03 Oct 2023 13:46:27 +0000 Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-32336a30d18so904670f8f.2 for ; Tue, 03 Oct 2023 06:46:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=cybertec-at.20230601.gappssmtp.com; s=20230601; t=1696340785; x=1696945585; darn=lists.postgresql.org; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:from:to:cc:subject:date :message-id:reply-to; bh=yXNZ6UfwomIA8/rUQgIJwkfryhR2lIXLmh6o8Mt2+n4=; b=bd8ngyBaPgvujpIqbjaCMykyIK6SEjONBuNTpKL8RutjsHwqvIC/7LeOi+P6japelK yeuoCKfRu8X+B/FfmUHppmkLnJHgDPkQ4FgeAJaaPXc19xQSYBh3E6H1hupfI9jA6x79 EFyNTgsLurmfcytzJOeO0VMyhRNFOg6fNOAe3+1tAXWSJ4NiTOiu9K6ImQPmKGu5DcS1 jRgXoR2X81ItI6sGeLpUClONaWYt/Yz1XhYW4cgvLzuB5KPLXHEcO67f2WTL/JU5BmsT 20JeplWi2kZamjdknY6RLiWdiWVvh/m6R6YAJ/01WGzBUIp2Cirek4wrVXHe1BOKljc0 jvDg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1696340785; x=1696945585; h=mime-version:user-agent:content-transfer-encoding:references :in-reply-to:date:to:from:subject:message-id:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to; bh=yXNZ6UfwomIA8/rUQgIJwkfryhR2lIXLmh6o8Mt2+n4=; b=Q88ebnU2gu7pgwyfMnAcBYHPj0lSsS8WtgrWxEizByEZ9tq192X/LTJhx9cJIlCk0A +9puhkfX0gr6RmLT9dhjqXhkrH0aBoCbQouWgfYCZrHHIVjjm9WPICzJqRpHUOTJhQBL K7mYuwkGYGKZDar2DIUFAtqVUyDCwuzNGvjsE/U4ryBDxK9DpL6oMV8zpYZPQNbc0ZeP MUnXnquiyITCy58thSa5UxqJvDN1ONTpvHV79YPU8S03qCLNMhuHOWZHH6KD9OJeyQT5 S88gWDFemGb4dJNdRFc1KUO3QkbFhpG1iaTEyoT0AusjbO5ey7TVhMpCJMVricYOg6l4 mNlA== X-Gm-Message-State: AOJu0YwysQ/dGu22+OnF6RWHtglGJvIiL6s11dcuQR4uwAIYNJD00ARu /1lCTcgq6iJDyHDcfRcfHEc7L2Eaq4PPijMLbjs= X-Google-Smtp-Source: AGHT+IG9CXEn8esQ1chFY0s8DDYSQawtl9Yob04STz4LhB5nw9Ua+uRjBni0zmIv7kaLgxYySiHt6Q== X-Received: by 2002:a05:6000:1006:b0:31f:9b4f:1910 with SMTP id a6-20020a056000100600b0031f9b4f1910mr11800581wrx.63.1696340784940; Tue, 03 Oct 2023 06:46:24 -0700 (PDT) Received: from localhost.localdomain ([2001:871:5e:1c0:45b9:97:dde5:9bad]) by smtp.gmail.com with ESMTPSA id z2-20020a5d6402000000b003197efd1e7bsm1613906wru.114.2023.10.03.06.46.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 Oct 2023 06:46:24 -0700 (PDT) Message-ID: <2bad53942920d2e501661af4cd49d6644a22b801.camel@cybertec.at> Subject: Re: unnest multirange, returned order From: Laurenz Albe To: daniel.fredouille@gmail.com, pgsql-docs@lists.postgresql.org Date: Tue, 03 Oct 2023 15:46:23 +0200 In-Reply-To: <169627213477.3727338.17653654241633692682@wrigleys.postgresql.org> References: <169627213477.3727338.17653654241633692682@wrigleys.postgresql.org> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 (3.48.4-1.fc38) MIME-Version: 1.0 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On Mon, 2023-10-02 at 18:42 +0000, PG Doc comments form wrote: > Page: https://www.postgresql.org/docs/16/functions-range.html >=20 > The doc says: > * unnest ( anymultirange ) =E2=86=92 setof anyrange > * Expands a multirange into a set of ranges. The ranges are read out in > storage order (ascending). >=20 > What is storage order ?=20 >=20 > At first I thought that it was the order in which the different ranges ar= e > inserted in the internal data structure. However, the following sort of > shows that it is not: > ``` > postgres=3D# select unnest('{[1,4), [8,10)}'::int4multirange + '{[-5,-3)}= ' - > '{[2,3)}') ; > =C2=A0unnest > --------- > =C2=A0[-5,-3) > =C2=A0[1,2) > =C2=A0[3,4) > =C2=A0[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 =20 =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2= =95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95= =90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90= =E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90=E2=95=90 {[-100,-50),[-1,2),[100,200)} (1 row) Yours, Laurenz Albe