From: Tom Lane <tgl@sss.pgh.pa.us>
To: David G. Johnston <david.g.johnston@gmail.com>
Cc: Brent Wood <Brent.Wood@niwa.co.nz>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: hstore each() function - returned order??
Date: Fri, 12 Mar 2021 09:52:13 -0500
Message-ID: <2439589.1615560733@sss.pgh.pa.us> (raw)
In-Reply-To: <CAKFQuwah6WyYRFV1geyuduUjp9fT=YKtXCv+2h-2c27eAg+mcQ@mail.gmail.com>
References: <SY3PR01MB0810FF20F164CE2536930B2CA16F9@SY3PR01MB0810.ausprd01.prod.outlook.com>
<CAKFQuwZqgS-RMhEXdBWj1PjpTVmGfeVMw_06EXnyAUe1WOgLVw@mail.gmail.com>
<SY3PR01MB0810712BBBB3DE3B46D4EDF5A16F9@SY3PR01MB0810.ausprd01.prod.outlook.com>
<CAKFQuwah6WyYRFV1geyuduUjp9fT=YKtXCv+2h-2c27eAg+mcQ@mail.gmail.com>
"David G. Johnston" <david.g.johnston@gmail.com> writes:
> On Fri, Mar 12, 2021 at 3:18 AM Brent Wood <Brent.Wood@niwa.co.nz> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, david.g.johnston@gmail.com, Brent.Wood@niwa.co.nz
Subject: Re: hstore each() function - returned order??
In-Reply-To: <2439589.1615560733@sss.pgh.pa.us>
References: <SY3PR01MB0810FF20F164CE2536930B2CA16F9@SY3PR01MB0810.ausprd01.prod.outlook.com> <CAKFQuwZqgS-RMhEXdBWj1PjpTVmGfeVMw_06EXnyAUe1WOgLVw@mail.gmail.com> <SY3PR01MB0810712BBBB3DE3B46D4EDF5A16F9@SY3PR01MB0810.ausprd01.prod.outlook.com> <CAKFQuwah6WyYRFV1geyuduUjp9fT=YKtXCv+2h-2c27eAg+mcQ@mail.gmail.com> <2439589.1615560733@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox