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 09:22:57
Message-ID: 5C5270F1-4323-458F-99C2-1D187039EA9C@gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general


> 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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Dominique Devienne 2023-05-09 09:37:29 Re: Return rows in input array's order?
Previous Message Dominique Devienne 2023-05-09 08:34:10 Return rows in input array's order?