GetNthElem function

The GetNthElem function extracts the entry at a particular offset or position in a time series.

Syntax

GetNthElem(ts     TimeSeries, 
           N       integer,
           flags   integer default 0) 
returns row;
ts
The source time series.
N
The offset or position of an entry in the time series. This value cannot be less than 0.
flags
Valid values for the flags argument are described in The flags argument values. The default is 0.

Description

For irregular time series, the GetNthElem function returns the Nth element that is found. For regular time series, the Nth element is also the Nth interval from the beginning of the time series.

The API equivalent of this function is ts_nth_elem().

Returns

A row value for the requested offset, including all the time series data at that timepoint and the time stamp of the entry in the time series' calendar. The type of the row is the same as the time series subtype.

If the offset is greater than the offset of the last element in the time series, NULL is returned.

Example

The following query returns the last element in a time series:
select GetNthElem(stock_data,GetNelems(stock_data)-1)
   from daily_stocks
   where stock_name = 'IBM';
The following query returns the element in a time series at a certain time stamp (this could also be done with GetElem):
select GetNthElem(stock_data,GetIndex(stock_data,
            '2011-01-04 00:00:00.00000'))
   from daily_stocks
   where stock_name = 'IBM';