我有一个包含以下架构的表,其中tstamp
是epoch:
Table "public.count_history"
Column | Type | Modifiers
--------+--------+-----------
data | text | not null
tstamp | bigint | not null
count | bigint | not null
Indexes:
"count_history_pkey" PRIMARY KEY, btree (data, tstamp)
我有以下自定义功能,可以帮助我将计数分组到#34;桶":
List of functions
Schema | Name | Result data type | Argument data types | Type | Security | Volatility | Owner | Language | Source code | Description
--------+----------+------------------+---------------------+--------+----------+------------+-------+----------+----------------------------+-------------
public | ts_round | bigint | bigint, bigint | normal | invoker | volatile | foo | sql | +|
| | | | | | | | | SELECT ($2 * ($1 / $2));+|
| | | | | | | | | |
我有以下查询,可以获取每个"桶的最大计数值"时间,这是24小时:
SELECT data, ts_round(tstamp, 86400) AS tstamp, max(count) AS count FROM count_history GROUP BY 2, 3;
有一段时间可能是空的,在这种情况下,在这段时间内不会返回一行。我怎么能继续使用前一行的count
值返回那段时间?