agora inbox for pgsql-docs@postgresql.org  
help / color / mirror / Atom feed
From: Laurenz Albe <laurenz.albe@cybertec.at>
To: s@xss.de
To: pgsql-docs@lists.postgresql.org
Subject: Re: Suggestion for docs, section "4.2.3 Subscripts": bounds and base
Date: Mon, 07 Apr 2025 10:03:47 +0200
Message-ID: <488788bd2526cec7eb175741c010cab2fa24fed4.camel@cybertec.at> (raw)
In-Reply-To: <174370454407.3115968.6902015899222362259@wrigleys.postgresql.org>
References: <174370454407.3115968.6902015899222362259@wrigleys.postgresql.org>

On Thu, 2025-04-03 at 18:22 +0000, PG Doc comments form wrote:
> Page: https://www.postgresql.org/docs/17/sql-expressions.html
> Description:
> 
> I skimmed over section 4.2 while waiting for a meeting to start and found no
> mention of the following two questions that immediately pop up in my mind
> when subscripts are mentionned:
> 
> Are subscripts 0-based or 1-based?

This question is answered in the documentation of the array data types:
https://www.postgresql.org/docs/current/arrays.html

  The array subscript numbers are written within square brackets. By default
  PostgreSQL uses a one-based numbering convention for arrays, that is, an
  array of n elements starts with array[1] and ends with array[n].

> Are slice boundaries inclusive or exclusive?

That becomes clear on the same page:

  We can also access arbitrary rectangular slices of an array, or subarrays.
  An array slice is denoted by writing lower-bound:upper-bound for one or
  more array dimensions. For example, this query retrieves the first item
  on Bill's schedule for the first two days of the week:

    SELECT schedule[1:2][1:1] FROM sal_emp WHERE name = 'Bill';

            schedule
    ------------------------
     {{meeting},{training}}
    (1 row)

Admittedly, there is no exact definition, but the example makes clear that
the boundaries are inclusive.

I don't think that we need to repeat that information.

Yours,
Laurenz Albe





view thread (3+ messages)  latest in thread

Message-ID: <488788bd2526cec7eb175741c010cab2fa24fed4.camel@cybertec.at>
Permalink:  ../488788bd2526cec7eb175741c010cab2fa24fed4.camel@cybertec.at/
Also on:    postgresql.org/message-id/488788bd2526cec7eb175741c010cab2fa24fed4.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, s@xss.de, pgsql-docs@lists.postgresql.org
  Subject: Re: Suggestion for docs, section "4.2.3 Subscripts": bounds and base
  In-Reply-To: <488788bd2526cec7eb175741c010cab2fa24fed4.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 agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox