Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pwJYy-00070B-JF for pgsql-general@arkaria.postgresql.org; Tue, 09 May 2023 09:23:16 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1pwJYx-0001Uv-ES for pgsql-general@arkaria.postgresql.org; Tue, 09 May 2023 09:23:15 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1pwJYx-0001St-2A for pgsql-general@lists.postgresql.org; Tue, 09 May 2023 09:23:15 +0000 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1pwJYu-001MM6-K8 for pgsql-general@postgresql.org; Tue, 09 May 2023 09:23:13 +0000 Received: by mail-pf1-x435.google.com with SMTP id d2e1a72fcca58-643990c5373so5462295b3a.1 for ; Tue, 09 May 2023 02:23:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1683624192; x=1686216192; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:from:to:cc:subject:date:message-id :reply-to; bh=M3yT+Z4U1CEG1BrssQ6GFSZdO7xVhVp3PL+lfRoCIb0=; b=NkslyMKwJTSab+AOJnJzUwySv8cMi6WrQRo3mY16a1I0r6VjPU95nhZY7VMdKc+hkE ZGj51FLox6XbtMcJ+N3tVd96WBUNDUY2nNFnG7hxkVusAQCOM9IuLjQJAt7bCXI5AwTa b8jwjN+RfZTVFYrawM+keGzQt83Nos59vLmvx/0P8LdMFYUzSl1y5c1weD+g3xSFeax/ G127lIWEeEWhAjbF4+4JMZgX6r7sJjOUft5F55Je2ja5bOnO6LFcLa/ro73fTEiPaj1R cChE7C4gvFKwI3bkDseSYsN57iLFhA0Lyqkw/OAYQNY12sgCq+lT7TpyDTkXA+z1j4WU F9vA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683624192; x=1686216192; h=to:in-reply-to:cc:references:message-id:date:subject:mime-version :from:content-transfer-encoding:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=M3yT+Z4U1CEG1BrssQ6GFSZdO7xVhVp3PL+lfRoCIb0=; b=NWp+aBsWL4SnrrgKvzW6W5Up4quz+Ls2T+nphwElwocTtwc5xAMLQk8Sho7XcAtz2p F7J4BvHW/2ZwbmyUSXb5pu3LOD9bK0Zh2G5ofmZ0gfVLj6dWOh3/tD1xRzelLCeAnyIG RDnCb6Mi/cuhgFn98vM6g6zLM8xBxWJQJGmv1VUFV/Enw09x3UUi/+IuYJrFfFFKB2oW jMMo6XhuhKbr1JnarqTljxFrRt0/UONjH3BdRweFVBx9LpDXjhwHV+Ebw1uSKrKg3i+1 uudVrNl6vh+VT740mYgvVE/NLEGdY4Cykn9r/naf3yxcsNL8FEhUUNrS5uh/Ee8uG+84 0ttQ== X-Gm-Message-State: AC+VfDzUOL2Ckdu5m+6ybGOQIItfbcTRJG3JmuBT2aFA0x9jCZRlOqXv aB4atLLABeXrP98OvONFnagAQUEOHsU= X-Google-Smtp-Source: ACHHUZ6cQGcIoo7Em6ystKSdd9+zuONpSjxOty6+qweta1FdaL1Msb+2LxkqjjxesNTOXfdDDGwhZQ== X-Received: by 2002:a05:6a20:7d84:b0:100:d88c:4a23 with SMTP id v4-20020a056a207d8400b00100d88c4a23mr5686680pzj.52.1683624191646; Tue, 09 May 2023 02:23:11 -0700 (PDT) Received: from smtpclient.apple (180-150-38-128.b49626.bne.nbn.aussiebb.net. [180.150.38.128]) by smtp.gmail.com with ESMTPSA id j23-20020aa79297000000b00642e9b3c868sm1332507pfa.59.2023.05.09.02.23.10 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 09 May 2023 02:23:11 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: David Wheeler Mime-Version: 1.0 (1.0) 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> References: Cc: pgsql-general@postgresql.org In-Reply-To: To: Dominique Devienne X-Mailer: iPhone Mail (20B101) List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk > Hi. With an integer identity primary key table, > we fetch a number of rows with WHERE id =3D 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. >=20 > Is it possible to maintain $1's order directly in SQL? Efficiently? We=E2=80=99ve done this before with an =E2=80=9Corder by array_index(id, inp= ut_array)=E2=80=9D. I forget the actual function consider that pseudo code It was only used for small arrays but never noticed any performance issues=