Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1taI8u-000UW7-QC for pgsql-general@arkaria.postgresql.org; Tue, 21 Jan 2025 17:34:25 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.94.2) (envelope-from ) id 1taI8t-002QtW-TB for pgsql-general@arkaria.postgresql.org; Tue, 21 Jan 2025 17:34:23 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.94.2) (envelope-from ) id 1taI8t-002QtN-If for pgsql-general@lists.postgresql.org; Tue, 21 Jan 2025 17:34:23 +0000 Received: from fhigh-b3-smtp.messagingengine.com ([202.12.124.154]) by makus.postgresql.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1taI8r-000lXM-1U for pgsql-general@lists.postgresql.org; Tue, 21 Jan 2025 17:34:22 +0000 Received: from phl-compute-04.internal (phl-compute-04.phl.internal [10.202.2.44]) by mailfhigh.stl.internal (Postfix) with ESMTP id 6017225401A4; Tue, 21 Jan 2025 12:34:21 -0500 (EST) Received: from phl-mailfrontend-01 ([10.202.2.162]) by phl-compute-04.internal (MEProxy); Tue, 21 Jan 2025 12:34:21 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1737480861; x=1737567261; bh=trEljIV36x1DqcS/Bp6jUgWWFv3mJHQIbmPuIixSnZY=; b= SvGQpMOMiEDVTp1sHxp5eAgSal6ta6p6joWqN3kHYIM0QLoAGg5AfJCfm1+Lzdmb gm7jQehFkWqbvJ8nH/24pze82Xf0m5pg8lr6UYvqNzzKmhbgG0vgz2DDXcrYcD+U cFz6XBXvZDUqqsqgLmDcsiAZ7RCJS3RVpUKcYqPixXjuz9s71GIwWzn5d8wwoAVl QFFziKn4iOcgEW7asgPPtu+nBzCMauSNuCPRPmfBqpxvKgLzQZeVRtNHYQBrlSHR K52Kneap7KsDcyPW9uGmF+dZebXetr9XslhYZoUXVf6ojvzyof9d1FHpMOxKTnws Tc6COhg67qE5ZHvZaU3HXQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :content-type:date:date:feedback-id:feedback-id:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:subject:subject:to:to:x-me-proxy:x-me-sender :x-me-sender:x-sasl-enc; s=fm3; t=1737480861; x=1737567261; bh=t rEljIV36x1DqcS/Bp6jUgWWFv3mJHQIbmPuIixSnZY=; b=UZTWd6AQhZEh3csv+ qiu8j+W81mO0cgR4zA4+qznWuUPo/uCaYXbD2b15vswDottwNHTUnhYZOjiPQZPF WMgslib/WJfxm9aaZe1llHDzzpDCiX0pMr3K/zi7OUMlM9B3XR8XH+uHMYeC3Hp6 efQ5mA+mRbq4PQ2dl2G1jom/eBR0y1Trki9ecqweFwN+Jib02GSMnJJMIjYZOl0x 8teweIID3tAyGXfvxf1DezgwI5S4EZ6wTYixjHVj09VrdhuYUW3czc9sOhLMJz/6 CTzAlMzUebb79Pi4bZncK+DsLNq1W6bpgsqhg2wcPuLwFSYLnnlxVhfs5PUUIk3I TZpWg== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefuddrudejvddgjedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh htshculddquddttddmnecujfgurhepkfffgggfuffvfhfhjggtgfesthekredttddvjeen ucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdrkhhlrghvvghrse grkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeffleegieefgfevudehtdfh keeutdffjeevgeffgeejvedthefgudeiteefheejheenucevlhhushhtvghrufhiiigvpe dtnecurfgrrhgrmhepmhgrihhlfhhrohhmpegrughrihgrnhdrkhhlrghvvghrsegrkhhl rghvvghrrdgtohhmpdhnsggprhgtphhtthhopedvpdhmohguvgepshhmthhpohhuthdprh gtphhtthhopegsrhgvnhhtrdifohhougesnhhifigrrdgtohdrnhiipdhrtghpthhtohep phhgshhqlhdqghgvnhgvrhgrlheslhhishhtshdrphhoshhtghhrvghsqhhlrdhorhhg X-ME-Proxy: Feedback-ID: i76984098:Fastmail Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue, 21 Jan 2025 12:34:20 -0500 (EST) Message-ID: <9d1dfa7a-4d1d-40c2-960e-5d9240217245@aklaver.com> Date: Tue, 21 Jan 2025 09:34:19 -0800 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: concatenating hstores in a group by? To: Brent Wood , "pgsql-general@lists.postgresql.org" References: <2268303.1737134384@sss.pgh.pa.us> Content-Language: en-US From: Adrian Klaver In-Reply-To: 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 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 adrian.klaver@aklaver.com