pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Charles Clavadetscher <clavadetscher@swisspug.org>
To: Brent Wood <Brent.Wood@niwa.co.nz>
Cc: pgsql-general@lists.postgresql.org
Subject: Re: hstore each() function - returned order??
Date: Fri, 12 Mar 2021 13:59:43 +0100
Message-ID: <e1d7f77272600b4b6bf5d6358a86be8f@swisspug.org> (raw)
In-Reply-To: <SY3PR01MB0810FF20F164CE2536930B2CA16F9@SY3PR01MB0810.ausprd01.prod.outlook.com>
References: <SY3PR01MB0810FF20F164CE2536930B2CA16F9@SY3PR01MB0810.ausprd01.prod.outlook.com>

Hi

On 2021-03-12 04:46, Brent Wood 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;
> 
> I'm assuming this will give two columns containing the key/value pairs
> in the hstore record.
> 
> The docs suggest the order of the keys/values returned is
> undetermined. That is a bit ambiguous to me.
> 
> The order is not a problem in this case: as long as the keys and
> values are returned in the SAME order, what that order is I don't
> care.
> 
> Just that the key is always returned in the same row as its value.
> 
> It does seem to work, at least in my test cases, but I need to know if
> that is just luck, or if it is a safe assumption to make.
> 
> Can anyone confirm this is a robust assumption for me?

You can order the result by key to have a specific order that remains 
between calls.

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

Bye
Charles

> 
> Thanks
> 
> Brent Wood
> 
> Principal Technician, Fisheries
> NIWA
> DDI:  +64 (4) 3860529
> 
>  		 [1]
> 
>  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 [1] Facebook [2] LinkedIn [3] Twitter
> [4] Instagram [5]
> 
>  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
> 
> Links:
> ------
> [1] https://www.niwa.co.nz
> [2] https://www.facebook.com/nzniwa
> [3] https://www.linkedin.com/company/niwa
> [4] https://twitter.com/niwa_nz
> [5] https://www.instagram.com/niwa_science

-- 
Charles Clavadetscher
Swiss PostgreSQL Users Group
Treasurer
Spitzackerstrasse 9
CH - 8057 Zürich

http://www.swisspug.org

+---------------------------+
|     ____  ______  ___     |
|    /    )/      \/   \    |
|   (     / __    _\    )   |
|    \    (/ o)  ( o)   )   |
|     \_  (_  )   \ ) _/    |
|       \  /\_/    \)/      |
|        \/ <//|  |\\>      |
|             _|  |         |
|             \|_/          |
|                           |
|     Swiss PostgreSQL      |
|       Users Group         |
|                           |
+---------------------------+





view thread (7+ messages)  latest in thread

Message-ID: <e1d7f77272600b4b6bf5d6358a86be8f@swisspug.org>
Permalink:  ../e1d7f77272600b4b6bf5d6358a86be8f@swisspug.org/
Also on:    postgresql.org/message-id/e1d7f77272600b4b6bf5d6358a86be8f@swisspug.org

 · 

reply

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: clavadetscher@swisspug.org, Brent.Wood@niwa.co.nz
  Subject: Re: hstore each() function - returned order??
  In-Reply-To: <e1d7f77272600b4b6bf5d6358a86be8f@swisspug.org>
  References: <SY3PR01MB0810FF20F164CE2536930B2CA16F9@SY3PR01MB0810.ausprd01.prod.outlook.com> <e1d7f77272600b4b6bf5d6358a86be8f@swisspug.org>

* 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