GetLastValid function

The GetLastValid function extracts the element for the given time stamp in a time series.

Syntax

GetLastValid(ts     TimeSeries, 
            tstamp datetime year to fraction(5),
            flags integer default 0) 
returns row;
ts
The source time series.
tstamp
The time stamp for the element.
flags
Valid values for the flags argument are described in The flags argument values. The default is 0.

Description

For regular time series, this function returns the element at the calendar's latest valid timepoint at or before the given time stamp. For irregular time series, it returns the latest element at or preceding the given time stamp.

The equivalent API function is ts_last_valid().

Returns

A row type containing the nearest element at or before the given time stamp. The type of the row is the same as the time series subtype.

If the time stamp is earlier than the origin of the time series, NULL is returned.

Example

The following query returns the last valid entry in a time series at or before a given time stamp:
select GetLastValid(stock_data, '2011-01-08 00:00:00.00000')
from daily_stocks
where stock_name = 'IBM';