pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: David Wheeler <hippysoyboy@gmail.com>
To: Dominique Devienne <ddevienne@gmail.com>
Cc: pgsql-general@postgresql.org
Subject: Re: Return rows in input array's order?
Date: Tue, 9 May 2023 20:35:55 +1000
Message-ID: <BAC27EA4-B883-4C12-AF6A-BAD76ADE5F28@gmail.com> (raw)
In-Reply-To: <CAFCRh-_w_b-12z1LO3u6C_enjbzGsSVN6PEZ4aZ5HYzBfdmioA@mail.gmail.com>
References: <CAFCRh-_w_b-12z1LO3u6C_enjbzGsSVN6PEZ4aZ5HYzBfdmioA@mail.gmail.com>


>> It was only used for small arrays but never noticed any performance issues
> 
> Hmmm, sounds like this would be quadratic though...

True, but it’s cpu time not io, which tends to be orders of magnitude slower

> I wonder whether the int[] can be turned into a pseudo table with a ROWNUM extra generated column that
> would then be (LEFT) JOIN'd to the accessed table, so that the original array index is readily accessible.
> Would something like this be possible in Postgres' SQL?

The unnest function mentioned above has a “with ordinality” option which gives easy access to the array index so a simple join would do the trick





view thread (11+ messages)  latest in thread

Message-ID: <BAC27EA4-B883-4C12-AF6A-BAD76ADE5F28@gmail.com>
Permalink:  ../BAC27EA4-B883-4C12-AF6A-BAD76ADE5F28@gmail.com/
Also on:    postgresql.org/message-id/BAC27EA4-B883-4C12-AF6A-BAD76ADE5F28@gmail.com

 · 

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: hippysoyboy@gmail.com, ddevienne@gmail.com
  Subject: Re: Return rows in input array's order?
  In-Reply-To: <BAC27EA4-B883-4C12-AF6A-BAD76ADE5F28@gmail.com>
  References: <CAFCRh-_w_b-12z1LO3u6C_enjbzGsSVN6PEZ4aZ5HYzBfdmioA@mail.gmail.com> <BAC27EA4-B883-4C12-AF6A-BAD76ADE5F28@gmail.com>

* 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