From: David G. Johnston <david.g.johns...@gmail.com>
Sent: Friday, March 12, 2021 21:19
To: Brent Wood <brent.w...@niwa.co.nz>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: hstore each() function - returned order??


Thanks David,

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;

I'll try it with \timing & explain to look at performance, but I don't see how 
this provides any greater assurance that the keys & values are provided in the 
same order, and so the correct value is in the same row as its key?

This still seems to depend on just how the EACH() function returns the values 
rather than any use of lateral joins, and was the question I was asking.

Cheers

Brent Wood

On Thursday, March 11, 2021, Brent Wood 
<brent.w...@niwa.co.nz<mailto:brent.w...@niwa.co.nz>> wrote:
Hi,

I'm using the following in an SQL :

select (EACH(value)).key as measurement_key,
       (EACH(value)).value as value
from t_reading_hstore;


Just move the each call to the from clause as a lateral join and treat the 
result as a two-column table.

David J.




[https://www.niwa.co.nz/static/niwa-2018-horizontal-180.png][https://niwa.co.nz/sites/niwa.co.nz/files/ETNZ_Official-supplier-logo-75h.png]<https://www.niwa.co.nz>
Brent Wood
Principal Technician - GIS and Spatial Data Management
Programme Leader - Environmental Information Delivery
+64-4-386-0529
National Institute of Water & Atmospheric Research Ltd (NIWA)
301 Evans Bay Parade Hataitai Wellington New Zealand
Connect with NIWA: niwa.co.nz<https://www.niwa.co.nz> 
Facebook<https://www.facebook.com/nzniwa> 
LinkedIn<https://www.linkedin.com/company/niwa> 
Twitter<https://twitter.com/niwa_nz> 
Instagram<https://www.instagram.com/niwa_science>
To ensure compliance with legal requirements and to maintain cyber security 
standards, NIWA's IT systems are subject to ongoing monitoring, activity 
logging and auditing. This monitoring and auditing service may be provided by 
third parties. Such third parties can access information transmitted to, 
processed by and stored on NIWA's IT systems

Reply via email to