public inbox for [email protected]  
help / color / mirror / Atom feed
From: Adrian Klaver <[email protected]>
To: Brent Wood <[email protected]>
To: [email protected] <[email protected]>
Subject: Re: concatenating hstores in a group by?
Date: Tue, 21 Jan 2025 09:34:19 -0800
Message-ID: <[email protected]> (raw)
In-Reply-To: <SY7P300MB0761B08085ED0691EBA1B78DA1E42@SY7P300MB0761.AUSP300.PROD.OUTLOOK.COM>
References: <CH2PR01MB5765698BB9F71CEB662D5AE4AD1B2@CH2PR01MB5765.prod.exchangelabs.com>
	<[email protected]>
	<SY7P300MB0761A579730344B2813CA07DA11B2@SY7P300MB0761.AUSP300.PROD.OUTLOOK.COM>
	<CAKFQuwasxOzkA-BECEaOz1b8EOh2hGaEfcG3JHquL-eDJkSrMQ@mail.gmail.com>
	<SY7P300MB0761B08085ED0691EBA1B78DA1E42@SY7P300MB0761.AUSP300.PROD.OUTLOOK.COM>

On 1/19/25 12:09, Brent Wood wrote:
> 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)

To be clear values_sec in t_reading_hstore_sec is the hstore field?

If so what is it's structure?

> 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
> 

-- 
Adrian Klaver
[email protected]







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], [email protected]
  Subject: Re: concatenating hstores in a group by?
  In-Reply-To: <[email protected]>

* 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