GetNthElem 函数

GetNthElem 函数抽取时间系列中特定偏移量或位置上的条目。

语法

GetNthElem(ts     TimeSeries, 
           N       integer,
           flags   integer default 0) 
returns row;
ts
源时间系列。
N
时间系列中条目的偏移量或位置。此值不能小于 0。
flags
flags 参数值中描述了 flags 参数的有效值。缺省值为 0

描述

对于不规则的时间系列,GetNthElem 函数返回找到的第 N 个元素。对于规则的时间系列,第 N 个元素也是从时间系列开头的算起的第 N 个时间间隔。

与此函数等效的 API 为 ts_nth_elem()

返回结果

请求偏移量的行值,包括该时间点的所有时间系列数据和条目在时间系列日历中的时间戳记。该行的类型与时间系列子类型相同。

如果偏移量大于时间系列中最后一个元素的偏移量,那么将返回 NULL

示例

以下查询返回时间系列中的最后一个元素:
select GetNthElem(stock_data,GetNelems(stock_data)-1)
   from daily_stocks
   where stock_name = 'GBase';
以下查询返回时间系列中某个时间戳记的元素(这也可以通过 GetElem 完成):
select GetNthElem(stock_data,GetIndex(stock_data,
            '2011-01-04 00:00:00.00000'))
   from daily_stocks
   where stock_name = 'GBase';