Return rows in input array's order?

From: Dominique Devienne <ddevienne(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Return rows in input array's order?
Date: 2023-05-09 08:34:10
Message-ID: CAFCRh-9qxbK5cwe=vooEaTPw+wZ1xQ+FDDnpWqRYEqzDwnSdgA@mail.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?

Currently the code assumes all PKs will be found. I.e. no "holes".
Would that assumption change the way it would be done in SQL?

Thanks, --DD

Responses

Browse pgsql-general by date

  From Date Subject
Next Message David Wheeler 2023-05-09 09:22:57 Re: Return rows in input array's order?
Previous Message Evgeny Morozov 2023-05-09 07:40:35 Re: "PANIC: could not open critical system index 2662" - twice