ApplyBinaryTsOp function
The ApplyBinaryTsOp function applies a binary arithmetic function to a pair of time series or to a time series and a compatible row type or number.
Syntax
ApplyBinaryTsOp(func_name lvarchar,
ts TimeSeries,
ts TimeSeries)
returns TimeSeries;
ApplyBinaryTsOp(func_name lvarchar,
number_or_row scalar|row,
ts TimeSeries)
returns TimeSeries;
ApplyBinaryTsOp(func_name lvarchar,
ts TimeSeries,
number_or_row scalar|row)
returns TimeSeries;
- func_name
- The name of a binary arithmetic function.
- ts
- The time series to use in the operation. The second and third arguments can be a time series, a row type, or a number. At least one of the two must be a time series.
- number_or_row
- A number or a row type to use in the operation. The second and third arguments can be a time series, a row type, or a number. The second two arguments must be compatible under the function. See Binary arithmetic functions for a description of the compatibility requirements.
Description
These functions operate in an analogous fashion to the arithmetic functions that have been overloaded to operate on time series. See the description of these functions in Binary arithmetic functions for more information. For example, Plus(ts1, ts2) is equivalent to ApplyBinaryTsOp(‘Plus', ts1, ts2).
Returns
A time series of the same type as the first time series argument, which can result in a loss of precision. The return type can be explicitly cast to a compatible time series type with more precision to avoid this problem. See Binary arithmetic functions for more information.
Example
create row type simple_series( stock_id int, data TimeSeries(one_real));
create table daily_high of type simple_series;
insert into daily_high
select stock_id,
Apply( '$0.high',
NULL::datetime year to fraction(5),
NULL::datetime year to fraction(5),
stock_data)::TimeSeries(one_real)
from daily_stocks;
create table daily_low of type simple_series;
insert into daily_low
select stock_id,
Apply( '$0.low',
NULL::datetime year to fraction(5),
NULL::datetime year to fraction(5),
stock_data)::TimeSeries(one_real)
from daily_stocks;
create table daily_avg of type simple_series;
insert into daily_avg
select l.stock_id, ApplyBinaryTSOp("plus", l.data, h.data)/2
from daily_low l, daily_high h
where l.stock_id = h.stock_id;
You can receive the same results by substituting (l.data + h.data) for ApplyBinaryTSOp('plus', 1.data, h.data).