Re: hstore each() function - returned order??

From: Brent Wood <pcreso(at)yahoo(dot)com>
To: "David G(dot) Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com>, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: Brent Wood <brent(dot)wood(at)niwa(dot)co(dot)nz>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: hstore each() function - returned order??
Date: 2021-03-12 20:44:12
Message-ID: 1348390418.377638.1615581852545@mail.yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Ahh, light dawns!!!
Thanks guys, much appreciated!!!  (as always)

Brent

On Saturday, March 13, 2021, 3:52:33 AM GMT+13, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> wrote:

"David G. Johnston" <david(dot)g(dot)johnston(at)gmail(dot)com> writes:
> On Fri, Mar 12, 2021 at 3:18 AM Brent Wood <Brent(dot)Wood(at)niwa(dot)co(dot)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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jan Wieck 2021-03-12 23:13:33 Re: pg_upgrade and wraparound
Previous Message Tom Lane 2021-03-12 14:52:13 Re: hstore each() function - returned order??