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 1lX9w6-00061Y-MS for pgsql-general@arkaria.postgresql.org; Thu, 15 Apr 2021 21:54:07 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1lX9w5-0002ip-5g for pgsql-general@arkaria.postgresql.org; Thu, 15 Apr 2021 21:54:05 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lX9w4-0002ih-L4 for pgsql-general@lists.postgresql.org; Thu, 15 Apr 2021 21:54:04 +0000 Received: from sonic315-21.consmr.mail.ne1.yahoo.com ([66.163.190.147]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.92) (envelope-from ) id 1lX9w0-0008Gh-9P for pgsql-general@lists.postgresql.org; Thu, 15 Apr 2021 21:54:03 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s2048; t=1618523636; bh=FktB1E/ABFaFv/Hqmukz/1joZCQiPxgogG6qbX4edkU=; h=Date:From:To:Cc:In-Reply-To:References:Subject:From:Subject:Reply-To; b=je9FPKgSDsP+S+xa571P/IFyuj5lTdNys2xreWhd0RXGZzRrS/0A3E4nPWTLkGbBMEmryrTuvBpjWKKLsCqmlwdz5w8fjBLqDPGJITzypx00COofOVakaBzQqWe0fK7H0DhJmAzLf8vVQHgJGa/cTJmxoogR4ibFmwNaQ9s4FlKOWHu2XIcf66ln+lOWo+98mR3hgRAWj18FOodFjSfHtC7ejwKWDh0tHJgCc3GU0VBtO7/WDJAYX8I2SiHYEl2y/fiCZ7aRi+miZGAQvaxbDqB/s/F8UgPNVHLIYrBfZbVxvv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TruPi1WBSwnMO.Hbn38b9QZHwhUkdwvtEP9tLW5exG3d BpstamHpo8wFkTQ-- X-Sonic-MF: Received: from sonic.gate.mail.ne1.yahoo.com by sonic315.consmr.mail.ne1.yahoo.com with HTTP; Thu, 15 Apr 2021 21:53:56 +0000 Date: Thu, 15 Apr 2021 21:53:15 +0000 (UTC) From: Brent Wood To: Mike Rylander Cc: Brent Wood , Michael Lewis , "pgsql-general@lists.postgresql.org" Message-ID: <1693555017.2585215.1618523595940@mail.yahoo.com> In-Reply-To: References: <288622710.2086083.1618435983252@mail.yahoo.com> Subject: Re: Timestamp/hstore query? MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="----=_Part_2585214_1420447400.1618523595937" X-Mailer: WebService/1.1.18121 YMailNorrin Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:87.0) Gecko/20100101 Firefox/87.0 Content-Length: 17058 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk ------=_Part_2585214_1420447400.1618523595937 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks Mike, That approach seems to work very well!!! There are something on the order of 40 billion readings in the table. This = returns an arbitrary one minutes data, as required, in under 30ms: SELECT distinct date_trunc('minute',_timer) as timer,=20 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 key::int,=20 =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=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A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0= =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 and '2020-04-15 08:10:5= 9' ) as x =C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2= =A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0=C2=A0 order= by key::int; v_sec is a view on a table with 30+ years of 1 second readings from dozens = of sensors, columns are timer (timestamp) & values (hstore). I used "between timestamps" rather than "=3D date_trunc()" in the where cla= use as this uses the index on timestamps, so is MUCH faster. FYI, we are using Timescaledb to manage the underlying data and data struct= ures. Appreciated!!! Brent Wood On Friday, April 16, 2021, 12:28:41 AM GMT+12, Mike Rylander wrote: =20 =20 On Wed, Apr 14, 2021 at 5:33 PM Brent Wood wrote: > > Thanks for your reply, > > The table is essentially: > create table readings (timer=C2=A0 =C2=A0 timestamp primary key, >=C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2=A0 =C2= =A0 =C2=A0 readings=C2=A0 hstore); > > the hstore comprises ( ) key/value pairs for readings= taken at the time specified in the timestamp. > > eg:=C2=A0 "67" "-45.67436", "68" "176.5424" could be key/value pairs repr= esenting latitude & longitude, with a timestamp in the timer column. > > There would be several lat/lon hstore pairs in a given minute, the query = I want would return the last one in the timeseries for that minute (for eac= h key). > > I don't think your examples will give me the separate hstore key-value pa= irs, extracted as the last in the interval for each key & reassembled as an= hstore list in the result. The sensor id is the hstore key, as described a= bove, not a separate attribute. That said, the keys can be extracted from t= he hstore much like a column, but I'm not sure that is the best approach. > > Treating each set of hstores in an interval as an array & extracting the = last elements may be viable. But I['m not sure how... > Hi Brent, With the table structure like that, you'll need to project all the sensor data onto each timestamp and then collapse it.=C2=A0 Something like this: =C2=A0 SELECT date_trunc('minute',timer), key, first(value) over (partition by key order by timer desc) FROM (SELECT timer, (each(readings)).* FROM table WHERE date_trunc('minute',timer) =3D '2021-04-15 08:10:00-04')x; If your queries will always target a specific timestamp truncated to the minute, you'll find an index on date_trunc('minute',timer) will be useful, I think.=C2=A0 If your intervals are more complex than date_trunc() can handle then you'll have to get more creative, but that's the basic structure -- normalize the primary key, project the sensor data to make it table-ish, then use regular SQL to pull out what you want. -- Mike Rylander | Research and Development Manager | Equinox Open Library Initiative | phone:=C2=A0 1-877-OPEN-ILS (673-6457) | email:=C2=A0 miker@equinoxOLI.org | web:=C2=A0 https://equinoxOLI.org > > > On Thursday, April 15, 2021, 6:33:08 AM GMT+12, Michael Lewis wrote: > > > > > > If you share example schema and desired output (like a dummy table or eve= n pseudo code SQL), then I'm sure many people could help you. Right now, th= e description of your desired result seems a bit unclear, at least to me. > > > If you wanted to run this hourly for the last 1 hour, it sounds a bit lik= e want this- > > select sensor_id, date_trunc( 'minute', timestamptz_field_name_here ), la= st( value_from_hstore ) over ( partition by sensor_id, date_trunc( 'minute'= , timestamptz_field_name_here ) ) as last_value_recorded > from data_table_here > where timestamptz_field_name_here BETWEEN NOW() - interval '1 hour' and N= OW() > group by sensor_id, date_trunc( 'minute', timestamptz_field_name_here ) > > > You could also use the left join "where is null" pattern to check that a = prior record in the minute period of time does not exist for that same key.= Something like this- > > select d1.sensor_id, date_trunc( 'minute', d1.timestamptz_field_name_here= ), d1.timestamptz_field_name_here as last_value_recorded > from data_table_here as d1 > left join data_table_here as prior_d1 ON prior_d1.sensor_id =3D d1.sensor= _id AND prior_d1.timestamptz_field_name_here < d1.timestamptz_field_name_he= re and prior_d1.timestamptz_field_name_here >=3D date_trunc( 'minute', d1.t= imestamptz_field_name_here ) > where d1.timestamptz_field_name_here BETWEEN NOW() - interval '1 hour' an= d NOW() > > > > > > =20 ------=_Part_2585214_1420447400.1618523595937 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
Thanks Mike,

That approach seems to work very well!!!

There are s= omething on the order of 40 billion readings in the table. This returns an = arbitrary one minutes data, as required, in under 30ms:

SELECT distinct date_trunc('minute',_timer)= as timer,
          =             &nb= sp;         key::int,
 &nb= sp;            =             &nb= sp;     first_value(value)
    &= nbsp;           &nbs= p;        OVER (partition by key order b= y _timer desc)
         &nb= sp;            =    FROM (SELECT timer as _timer,
    &nbs= p;            &= nbsp;           &nbs= p;        (each(v.values)).*
 &n= bsp;            = ;            &n= bsp;    FROM v_sec v
      =             &nb= sp;            WHERE= timer between '2020-04-15 08:10:00'
      = ;            &n= bsp;            = ;            &n= bsp;   and '2020-04-15 08:10:59' ) as x
   &nbs= p;            &= nbsp;        order by key::int;


v_= sec is a view on a table with 30+ years of 1 second readings from dozens of= sensors, columns are timer (timestamp) & values (hstore).

I used "between timestamps" rather than "=3D date_trunc()" in the whe= re clause as this uses the index on timestamps, so is MUCH faster.

FYI, we are using Ti= mescaledb to manage the underlying data and data structures.



Appreciated!!!

Brent Wood
=


=20
=20
On Friday, April 16, 2021, 12:28:41 AM GMT+12, Mike Ryl= ander <mrylander@gmail.com> wrote:


On Wed, Apr 14, 2021 at 5:33 PM Brent= Wood <pcreso@yahoo.com> wrote:
>=
> Thanks for your reply,
>
> The table is essentially:
> create t= able readings (timer    timestamp primary key,
= >                    &= nbsp;   readings  hstore);
>
> the hstore comprises (<sensor_id> <reading>) key/value = pairs for readings taken at the time specified in the timestamp.
>
> eg:  "67" "-45.67436", "68" "176= .5424" could be key/value pairs representing latitude & longitude, with= a timestamp in the timer column.
>
= > There would be several lat/lon hstore pairs in a given minute, the que= ry I want would return the last one in the timeseries for that minute (for = each key).
>
> I don't think your= examples will give me the separate hstore key-value pairs, extracted as th= e last in the interval for each key & reassembled as an hstore list in = the result. The sensor id is the hstore key, as described above, not a sepa= rate attribute. That said, the keys can be extracted from the hstore much l= ike a column, but I'm not sure that is the best approach.
>
> Treating each set of hstores in an interval as= an array & extracting the last elements may be viable. But I['m not su= re how...
>

Hi Br= ent,

With the table structure like tha= t, you'll need to project all the
sensor data onto each t= imestamp and then collapse it.  Something like
this:=

  SELECT date_trunc('minute',tim= er), key, first(value) over (partition
by key order by ti= mer desc) FROM (SELECT timer, (each(readings)).*
FROM tab= le WHERE date_trunc('minute',timer) =3D '2021-04-15
08:10= :00-04')x;

If your queries will always= target a specific timestamp truncated to
the minute, you= 'll find an index on date_trunc('minute',timer) will be
u= seful, I think.  If your intervals are more complex than date_trunc()<= br clear=3D"none">can handle then you'll have to get more creative, but tha= t's the basic
structure -- normalize the primary key, pro= ject the sensor data to
make it table-ish, then use regul= ar SQL to pull out what you want.

--Mike Rylander
| Research and Developmen= t Manager
| Equinox Open Library Initiative
| phone:  1-877-OPEN-ILS (673-6457)
| email:=   miker@equinoxOLI.org
| web:&nb= sp; https://equinoxOLI.org


>= ;
>
> On Thursday, April 15, 2021= , 6:33:08 AM GMT+12, Michael Lewis <mlewis@entrata.com&= gt; wrote:
>
>
= >
>
>
> I= f you share example schema and desired output (like a dummy table or even p= seudo code SQL), then I'm sure many people could help you. Right now, the d= escription of your desired result seems a bit unclear, at least to me.
>
>
> If you wan= ted to run this hourly for the last 1 hour, it sounds a bit like want this-=
>
> select sensor_id, date_trunc= ( 'minute', timestamptz_field_name_here ), last( value_from_hstore ) over (= partition by sensor_id, date_trunc( 'minute', timestamptz_field_name_here = ) ) as last_value_recorded
> from data_table_here
> where timestamptz_field_name_here BETWEEN NOW() - interv= al '1 hour' and NOW()
> group by sensor_id, date_trunc= ( 'minute', timestamptz_field_name_here )
>
>
> You could also use the left join "whe= re is null" pattern to check that a prior record in the minute period of ti= me does not exist for that same key. Something like this-
>
> select d1.sensor_id, date_trunc( 'minute', d1.= timestamptz_field_name_here ), d1.timestamptz_field_name_here as last_value= _recorded
> from data_table_here as d1
> left join data_table_here as prior_d1 ON prior_d1.sensor_id =3D d1.= sensor_id AND prior_d1.timestamptz_field_name_here < d1.timestamptz_fiel= d_name_here and prior_d1.timestamptz_field_name_here >=3D date_trunc( 'm= inute', d1.timestamptz_field_name_here )
> where d1.ti= mestamptz_field_name_here BETWEEN NOW() - interval '1 hour' and NOW()
>
>
> >
>
>
------=_Part_2585214_1420447400.1618523595937--