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 19:22:57 +1000
Message-ID: <5C5270F1-4323-458F-99C2-1D187039EA9C@gmail.com> (raw)
In-Reply-To: <CAFCRh-9qxbK5cwe=vooEaTPw+wZ1xQ+FDDnpWqRYEqzDwnSdgA@mail.gmail.com>
References: <CAFCRh-9qxbK5cwe=vooEaTPw+wZ1xQ+FDDnpWqRYEqzDwnSdgA@mail.gmail.com>
> Hi. With an integer identity primary key table,
> we fetch a number of rows with WHERE id = ANY($1),
> with $1 an int[] array. The API using that query must return
> rows in the input int[] array order, and uses a client-side
> mapping to achieve that currently.
>
> Is it possible to maintain $1's order directly in SQL? Efficiently?
We’ve done this before with an “order by array_index(id, input_array)”. I forget the actual function consider that pseudo code
It was only used for small arrays but never noticed any performance issues
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: <5C5270F1-4323-458F-99C2-1D187039EA9C@gmail.com>
References: <CAFCRh-9qxbK5cwe=vooEaTPw+wZ1xQ+FDDnpWqRYEqzDwnSdgA@mail.gmail.com> <5C5270F1-4323-458F-99C2-1D187039EA9C@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