pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Combining array slicing and indexing causes incorrect/confusing results
2+ messages / 2 participants
[nested] [flat]

* Combining array slicing and indexing causes incorrect/confusing results
@ 2025-01-21 16:35 Jelte Fennema-Nio <me@jeltef.nl>
  2025-01-21 17:04 ` Re: Combining array slicing and indexing causes incorrect/confusing results Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 2+ messages in thread

From: Jelte Fennema-Nio @ 2025-01-21 16:35 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org

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)





^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: Combining array slicing and indexing causes incorrect/confusing results
  2025-01-21 16:35 Combining array slicing and indexing causes incorrect/confusing results Jelte Fennema-Nio <me@jeltef.nl>
@ 2025-01-21 17:04 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 2+ messages in thread

From: Tom Lane @ 2025-01-21 17:04 UTC (permalink / raw)
  To: Jelte Fennema-Nio <me@jeltef.nl>; +Cc: pgsql-bugs@lists.postgresql.org

Jelte Fennema-Nio <me@jeltef.nl> writes:
> 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.

Well, yeah, because they're fundamentally different operations.
A slice produces a value of the array type, a regular index
operation produces a value of the element type.  So if you
mix the notations we assume you really meant slicing in each
subscript.

			regards, tom lane





^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2025-01-21 17:04 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2025-01-21 16:35 Combining array slicing and indexing causes incorrect/confusing results Jelte Fennema-Nio <me@jeltef.nl>
2025-01-21 17:04 ` Tom Lane <tgl@sss.pgh.pa.us>

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