Re: concatenating hstores in a group by?

From: Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>
To: Brent Wood <Brent(dot)Wood(at)niwa(dot)co(dot)nz>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: concatenating hstores in a group by?
Date: 2025-01-19 16:16:23
Message-ID: 53b84a62-5aa7-4cd6-bb81-ef79bc8f93af@aklaver.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 1/17/25 12:43, Brent Wood wrote:
> Hi,
>
> I have a table with a timestamp and hstore columns with times in
> milliseconds.
>
> I want to concatenate the hstores, grouped by timestamp, with the
> timestamps truncated to whole seconds: date_trunc('seconds', timer).
>
> How can I concatenate all the hstores within a one second interval,
>
>  ie, something like:
>
> select timer,
>               <hstores concatenated>
> from (select  date_trunc('seconds', timer) as timer_sec, hstore)
> group by timer;

1) This is going to need some example data and the table definition.

2) The above query does not make sense.

3) Hstore does not store duplicate key values:

From here:

https://www.postgresql.org/docs/current/hstore.html#HSTORE-OPS-FUNCS

select 'a=>b, c=>d'::hstore || 'c=>x, d=>q'::hstore ;
?column?
------------------------------
"a"=>"b", "c"=>"x", "d"=>"q"

Are there duplicated keys and if so how do you want to handle them?

>
>
> Thanks
>
>
> Brent Wood
>
> Principal Technician, Fisheries
> NIWA
> DDI:  +64 (4) 3860529
>

--
Adrian Klaver
adrian(dot)klaver(at)aklaver(dot)com

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2025-01-19 16:44:53 Re: concatenating hstores in a group by?
Previous Message auxsvr 2025-01-19 16:06:12 Re: Design of a reliable task processing queue