public inbox for [email protected]
help / color / mirror / Atom feedFrom: Brent Wood <[email protected]>
To: [email protected] <[email protected]>
Subject: Re: concatenating hstores in a group by?
Date: Sun, 19 Jan 2025 20:09:48 +0000
Message-ID: <SY7P300MB0761B08085ED0691EBA1B78DA1E42@SY7P300MB0761.AUSP300.PROD.OUTLOOK.COM> (raw)
In-Reply-To: <CAKFQuwasxOzkA-BECEaOz1b8EOh2hGaEfcG3JHquL-eDJkSrMQ@mail.gmail.com>
References: <CH2PR01MB5765698BB9F71CEB662D5AE4AD1B2@CH2PR01MB5765.prod.exchangelabs.com>
<[email protected]>
<SY7P300MB0761A579730344B2813CA07DA11B2@SY7P300MB0761.AUSP300.PROD.OUTLOOK.COM>
<CAKFQuwasxOzkA-BECEaOz1b8EOh2hGaEfcG3JHquL-eDJkSrMQ@mail.gmail.com>
Thanks for the replies, appreciated...
My current solution is:
select trip_code,
station_no,
timer_sec + interval '12 hour' as NZST,
timer_sec as utc,
hstore_to_json(string_agg(values_sec::text, ', ')::hstore) as values_sec
from (select '$TRIP' as trip_code,
$STATION as station_no,
date_trunc('second', timer) as timer_sec,
values_sec
from t_reading_hstore_sec
where timer >= '$ISO_S'::timestamp - interval '12 hour'
and timer <= '$ISO_F'::timestamp - interval '12 hour') as foo
group by timer_sec, trip_code, station_no;
Convert the hstore to text, aggregate the text with string_agg(), convert back to hstore (which seems to remove duplicate keys, OK for my purpose)
and group by timer truncated to whole seconds. I also provide UTC & local timezone times for each set of readings. It is run in a bash script which passes the trip & station values to the query, as well as the start/finish times as ISO format strings.
The output is going to a Sqlite3 (Spatialite) database, which does not have hstore, or all the hstore functionality that Postgres has, but does have a json datatype which is adequate for our purposes, hence the hstore_to_json in the query.
Thanks again,
Brent Wood
Principal Technician, Fisheries
NIWA
DDI: +64 (4) 3860529
________________________________
From: David G. Johnston <[email protected]>
Sent: Monday, January 20, 2025 04:28
To: Brent Wood <[email protected]>
Cc: [email protected] <[email protected]>
Subject: concatenating hstores in a group by?
On Friday, January 17, 2025, Brent Wood <[email protected]<mailto:[email protected]>> wrote:
I want to concatenate the hstores,
There are no hstore aggregate functions. You’ll want to convert them to,json first then use the json_objectagg aggregate function.
David J.
[https://www.niwa.co.nz/static/niwa-2018-horizontal-180.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; YouTube<https://www.youtube.com/channel/UCJ-j3MLMg1H59Ak2UaNLL3A;
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.
Note: This email is intended solely for the use of the addressee and may contain information that is confidential or subject to legal professional privilege. If you receive this email in error please immediately notify the sender and delete the email.
view thread (8+ messages) latest in thread
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 using the --to and --cc options:
reply via email
To: [email protected]
Cc: [email protected], [email protected]
Subject: Re: concatenating hstores in a group by?
In-Reply-To: <SY7P300MB0761B08085ED0691EBA1B78DA1E42@SY7P300MB0761.AUSP300.PROD.OUTLOOK.COM>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox