Re: Return rows in input array's order?

From: David Wheeler <hippysoyboy(at)gmail(dot)com>
To: Dominique Devienne <ddevienne(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Return rows in input array's order?
Date: 2023-05-09 10:35:55
Message-ID: BAC27EA4-B883-4C12-AF6A-BAD76ADE5F28@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


>> 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message shveta malik 2023-05-09 10:53:24 Re: Support logical replication of DDLs
Previous Message negora 2023-05-09 09:57:46 Re: Return rows in input array's order?