Combining array slicing and indexing causes incorrect/confusing results

From: Jelte Fennema-Nio <me(at)jeltef(dot)nl>
To: pgsql-bugs(at)lists(dot)postgresql(dot)org
Subject: Combining array slicing and indexing causes incorrect/confusing results
Date: 2025-01-21 16:35:17
Message-ID: CAGECzQR+CUuHDYOooGO5y87nRJnw_sjOvPVBUt7pmg2vopgc7w@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Due to the way SubscriptingRef works there's no way for it to describe
a subscript sequence that both does a slice and a regular index in the
same SubscriptingRef. This results into weird behaviour like the
following:

> select ('{1, 2, 3, 4}'::int[])[1:4][2];
int4
──────
{}
(1 row)

It's possible to get the expected result by adding some additional parenthesis

> select (('{1, 2, 3, 4}'::int[])[1:4])[2];
int4
──────
2
(1 row)

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2025-01-21 17:04:56 Re: Combining array slicing and indexing causes incorrect/confusing results
Previous Message PG Bug reporting form 2025-01-21 15:30:46 BUG #18782: Inconsistent behaviour with triggers and row level security - depends on prior number of inserts