PutElem function

The PutElem function adds an element to a time series at the timepoint indicated in the supplied row type.

Syntax

PutElem(ts         TimeSeries, 
       row_value  row,
       flags      integer default 0) 
returns TimeSeries;
ts
The time series to act on.
row_value
The new row type value to store in the time series.
flags
Valid values for the flags argument are described in The flags argument values. The default is 0.

Description

If the time stamp is NULL, the data is appended to the time series (for regular time series) or an error is raised (for irregular time series).

For regular time series, if there is data at the given timepoint, it is updated with the new data; otherwise, the new data is inserted.

For irregular time series, if there is no data at the given timepoint, the new data is inserted. If there is data at the given timepoint, the following algorithm is used to determine where to place the data:
  1. Round the time stamp up to the next second.
  2. Search backwards for the first element less than the new time stamp.
  3. Insert the new data at this time stamp plus 10 microseconds.

The row type passed in must match the subtype of the time series.

Hidden elements cannot be updated.

The API equivalent of PutElem is ts_put_elem().

Returns

A modified time series that includes the new values.

Example

The following example appends an element to a time series:
update daily_stocks
set stock_data = PutElem(stock_data,
   row(NULL::datetime year to fraction(5), 
   2.3, 3.4, 5.6, 67)::stock_bar)
   where stock_name = 'IBM';
The following example updates a time series:
update activity_stocks
set activity_data = PutElem(activity_data,
   row('2011-08-25 09:06:00.00000', 
      6.25, 1000, 1, 007, 2, 1)::stock_trade)
   where stock_id = 600;