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 1lKj9J-0003qp-QI for pgsql-general@arkaria.postgresql.org; Fri, 12 Mar 2021 14:52:21 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lKj9I-00019J-Nt for pgsql-general@arkaria.postgresql.org; Fri, 12 Mar 2021 14:52:20 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKj9I-00016t-FL for pgsql-general@lists.postgresql.org; Fri, 12 Mar 2021 14:52:20 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKj9E-00049n-Q5 for pgsql-general@lists.postgresql.org; Fri, 12 Mar 2021 14:52:19 +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 12CEqDJ82439590; Fri, 12 Mar 2021 09:52:13 -0500 From: Tom Lane To: "David G. Johnston" cc: Brent Wood , "pgsql-general@lists.postgresql.org" Subject: Re: hstore each() function - returned order?? In-reply-to: References: Comments: In-reply-to "David G. Johnston" message dated "Fri, 12 Mar 2021 07:28:32 -0700" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <2439588.1615560733.1@sss.pgh.pa.us> Date: Fri, 12 Mar 2021 09:52:13 -0500 Message-ID: <2439589.1615560733@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk "David G. Johnston" writes: > On Fri, Mar 12, 2021 at 3:18 AM Brent Wood wrote: >> Is this what you mean? >> >> select measurement_key, >> value >> from t_reading_hstore, >> lateral ((EACH(value)).key as measurement_key, >> lateral ((EACH(value)).value as value; > The definition of "each" shows that it returns a record type. That whole > type can be considered a table and referenced in the select list. Yeah. To my mind, the main point here is to run each() just once per t_reading_hstore row, not twice. So something like SELECT e.key, e.value FROM t_reading_hstore AS t, each(t.value) AS e; (Writing LATERAL is optional.) regards, tom lane