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 1opdPI-0006C8-MO for pgsql-sql@arkaria.postgresql.org; Mon, 31 Oct 2022 22:37:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1opdPH-000158-7R for pgsql-sql@arkaria.postgresql.org; Mon, 31 Oct 2022 22:37:23 +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 1opdPG-00014z-4y for pgsql-sql@lists.postgresql.org; Mon, 31 Oct 2022 22:37:22 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1opdPD-00085V-EU for pgsql-sql@lists.postgresql.org; Mon, 31 Oct 2022 22:37:21 +0000 Received: from compute3.internal (compute3.nyi.internal [10.202.2.43]) by mailout.nyi.internal (Postfix) with ESMTP id 5A9115C00BD; Mon, 31 Oct 2022 18:37:18 -0400 (EDT) Received: from imap51 ([10.202.2.101]) by compute3.internal (MEProxy); Mon, 31 Oct 2022 18:37:18 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=fastmail.com; h= cc:content-type:date:date:from:from:in-reply-to:in-reply-to :message-id:mime-version:references:reply-to:sender:subject :subject:to:to; s=fm3; t=1667255838; x=1667342238; bh=o/mak2PWhj OXncIWh43XXElrmt/WWyXbKstYn5NtySA=; b=aQiTx5hpn5mWxql/f9/ApKO5iM x6Ctv6s0eUZqz+5LD9HSobX5RvCZx2tdFEmKlqcXT2IehiUxvt0vXdPWGJ+6B1cX EMpn3H8mlZ27Npi73KmEnXfzmtnyVYTnGb14GvlglW0RP/XB4OG8F44NROmBNXdV u25a/Pw34zUv0VwZIR06xdK+QOBWIdRsZz5INuRCoUfohJ4pm7WfAMLSsQKXMKCF y0tYZBc9p2AwFCqcAOgY+GKCbvJZGcWCU2ALDXBDsFv9l9/YdsoNMCCag3xw86z9 CxXZqNoGGmqvejPIAuaAP/602zM4/LDkLLX3uRiDz52tcIHHW1maCX0b2Ojg== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-type:date:date:feedback-id :feedback-id:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; t=1667255838; x=1667342238; bh=o/mak2PWhjOXncIWh43XXElrmt/W WyXbKstYn5NtySA=; b=ZwaWVw2zcj4CVWsBjXWEUeWb8/gjxL2VDP2DY6R3P5Dk wYbA1ZDvqon+NibCR1Qu+Vgk/02wmnYhgQ7ggFIC1V8pWxvs9JkWipqeBeToO7yL DWeYMW93vPWJOGCuOX1DDRasVkP09jCXW7+LYBDukt8W1xcGRNCDSpibNjlnogcD 1PO6Fif+IXDsYaTyCyykEB7GIZOPJoTezK6xji8PLel9LhIHzTxnpEM3mj5jyO5H WFvb8QjDTiMWr5s6KP2BxQ+A8RkeLbbuCOtEQvcLYb5+Fu0SBCu7zcg0t7P/zJiB KZVHIuQDKBsRHf6YDMmt0ZjvY6WLhxrgwgD9xFJyEA== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvgedrudeggddtudcutefuodetggdotefrodftvf curfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfghnecu uegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenuc fjughrpefofgggkfgjfhffhffvufgtsegrtderreerreejnecuhfhrohhmpedfvfhorhhs thgvnhcuifhruhhsthdfuceothgvghhghiesfhgrshhtmhgrihhlrdgtohhmqeenucggtf frrghtthgvrhhnpefhudfgleehfeelteekhfdvteevieekkeejudeufffhvdejgfeuudeu vdelveevueenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhroh hmpehtvghgghihsehfrghsthhmrghilhdrtghomh X-ME-Proxy: Feedback-ID: i51c14773:Fastmail Received: by mailuser.nyi.internal (Postfix, from userid 501) id BC322B60086; Mon, 31 Oct 2022 18:37:17 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.7.0-alpha0-1087-g968661d8e1-fm-20221021.001-g968661d8 Mime-Version: 1.0 Message-Id: <31612ff3-67a4-4781-b359-0d182f73fe84@betaapp.fastmail.com> In-Reply-To: <5fb866d1-8d2f-5118-18e2-9bbf227cbf1a@gmail.com> References: <5fb866d1-8d2f-5118-18e2-9bbf227cbf1a@gmail.com> Date: Mon, 31 Oct 2022 23:36:56 +0100 From: "Torsten Grust" To: "Rob Sargent" , pgsql-sql Subject: Re: access sub elements using any() Content-Type: multipart/alternative; boundary=f18ba19a0be34eb2ab9f8107263433d2 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk --f18ba19a0be34eb2ab9f8107263433d2 Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Hi, On Mon, Oct 31, 2022, at 18:04, Rob Sargent wrote: > Given an array of arrays ( e.g. v =3D {{1,'a'},{2,'b'},{3,'c'},{2,'d'}= } ) is it possible, in plain sql, to access the first element of the lis= ted arrays using the IN function? Say I wanted just those with 2 as fir= st element. "where 2 =3D any(v[1])" does not work and not sure it's sup= ported. And I cannot craft a lhs to fussy-match each of the elements i= n v. Can this be done? if your inner arrays would be row values instead, i.e. if v would read v =3D array[(1,'a'),(2,'b'),(3,'c'),(2,'d')] :: t[] assuming CREATE TYPE t AS (x int, y text); then your query could simply be SELECT r.* FROM unnest(v) AS r WHERE r.x =3D 2; Cheers, =E2=80=94Torsten -- | Torsten Grust | teggy@fastmail.com --f18ba19a0be34eb2ab9f8107263433d2 Content-Type: text/html;charset=utf-8 Content-Transfer-Encoding: quoted-printable
Hi,

On Mon, Oct 31, 2022, at 18:04, Rob Sargent wrote:
=

=

if your inner arrays would be row values instead, i.= e. if v would read

  v =3D array= [(1,'a'),(2,'b'),(3,'c'),(2,'d')] :: t[]
  assuming C= REATE TYPE t AS (x int, y text);

then your = query could simply be

  SELECT r.*
=
  FROM   unnest(v) AS r
  W= HERE  r.x =3D 2;

Cheers,
&nb= sp; =E2=80=94Torsten

--
<= div class=3D"signature">| Torsten Grust


--f18ba19a0be34eb2ab9f8107263433d2--