Re: Timestamp/hstore query?

Поиск
Список
Период
Сортировка
От Michael Lewis
Тема Re: Timestamp/hstore query?
Дата
Msg-id CAHOFxGqbjSOuzzTwDAG=YEQ07rd-WszvBOq47PAiTLZNZwdjqA@mail.gmail.com
обсуждение исходный текст
Ответ на Timestamp/hstore query?  (Brent Wood <Brent.Wood@niwa.co.nz>)
Ответы Re: Timestamp/hstore query?  (Brent Wood <pcreso@yahoo.com>)
Список pgsql-general
If you share example schema and desired output (like a dummy table or even pseudo code SQL), then I'm sure many people could help you. Right now, the 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 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() - interval '1 hour' and NOW()
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 = d1.sensor_id AND prior_d1.timestamptz_field_name_here < d1.timestamptz_field_name_here and prior_d1.timestamptz_field_name_here >= date_trunc( 'minute', d1.timestamptz_field_name_here )
where d1.timestamptz_field_name_here BETWEEN NOW() - interval '1 hour' and NOW()

В списке pgsql-general по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Question about PG_CONTROL_VERSION 1
Следующее
От: Brent Wood
Дата:
Сообщение: Re: Timestamp/hstore query?