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 1lKhOX-0007tO-0Y for pgsql-general@arkaria.postgresql.org; Fri, 12 Mar 2021 12:59:57 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lKhOV-0007Xk-VM for pgsql-general@arkaria.postgresql.org; Fri, 12 Mar 2021 12:59:55 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKhOV-0007Uh-NJ for pgsql-general@lists.postgresql.org; Fri, 12 Mar 2021 12:59:55 +0000 Received: from gandalf.net-wizard.org ([138.201.143.9]) by makus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lKhOO-0008G5-Ls for pgsql-general@lists.postgresql.org; Fri, 12 Mar 2021 12:59:54 +0000 Received: from localhost (localhost [127.0.0.1]) by mail.net-wizard.org (Postfix) with ESMTP id C4F1782D7E; Fri, 12 Mar 2021 13:59:44 +0100 (CET) X-Virus-Scanned: Gentoo amavisd-new at aragorn Received: from aragorn.net-wizard.org ([127.0.0.1]) by localhost (aragorn.net-wizard.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id kiXt6AFMQS2Q; Fri, 12 Mar 2021 13:59:43 +0100 (CET) Received: from webmail.net-wizard.org (localhost [IPv6:::1]) by gandalf.net-wizard.org (Postfix) with ESMTP id 61EA582CB9; Fri, 12 Mar 2021 13:59:43 +0100 (CET) MIME-Version: 1.0 Date: Fri, 12 Mar 2021 13:59:43 +0100 From: Charles Clavadetscher To: Brent Wood Cc: pgsql-general@lists.postgresql.org Subject: Re: hstore each() function - returned order?? In-Reply-To: References: User-Agent: Roundcube Webmail/1.4.11 Message-ID: X-Sender: clavadetscher@swisspug.org Organization: Swiss PostgreSQL Users Group Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk 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 | | | +---------------------------+