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 1opfTs-0003KI-Md for pgsql-sql@arkaria.postgresql.org; Tue, 01 Nov 2022 00:50: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 1opfTr-0003Hz-2w for pgsql-sql@arkaria.postgresql.org; Tue, 01 Nov 2022 00:50: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 1opfTq-0003FQ-Lp for pgsql-sql@lists.postgresql.org; Tue, 01 Nov 2022 00:50:14 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1opfTj-0000m9-Vy for pgsql-sql@lists.postgresql.org; Tue, 01 Nov 2022 00:50:13 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.15.2/8.15.2) with ESMTP id 2A10o6HS1046907; Mon, 31 Oct 2022 20:50:06 -0400 From: Tom Lane To: Rob Sargent cc: pgsql-sql Subject: Re: access sub elements using any() In-reply-to: <5fb866d1-8d2f-5118-18e2-9bbf227cbf1a@gmail.com> References: <5fb866d1-8d2f-5118-18e2-9bbf227cbf1a@gmail.com> Comments: In-reply-to Rob Sargent message dated "Mon, 31 Oct 2022 11:04:00 -0600" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <1046905.1667263806.1@sss.pgh.pa.us> Date: Mon, 31 Oct 2022 20:50:06 -0400 Message-ID: <1046906.1667263806@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk Rob Sargent writes: > Given an array of arrays ( e.g. v = {{1,'a'},{2,'b'},{3,'c'},{2,'d'}} ) > is it possible, in plain sql, to access the first element of the listed > arrays using the IN function? If it's actually a 2-D array, and not an array-of-composite which is what your sample data seems to suggest, then array slicing might help: regression=# select ('{{1,2},{3,4},{5,6}}'::int[])[:][1]; int4 --------------- {{1},{3},{5}} (1 row) regression=# select 2 = any (('{{1,2},{3,4},{5,6}}'::int[])[:][1]); ?column? ---------- f (1 row) regression=# select 3 = any (('{{1,2},{3,4},{5,6}}'::int[])[:][1]); ?column? ---------- t (1 row) regards, tom lane