Map Lambda
The map() Lambda maps each element of the timevector. This Lambda must return either a DOUBLE PRECISION, where only the values of each point in the timevector is altered, or a (TIMESTAMPTZ, DOUBLE PRECISION), where both the times and values are changed. An example of the map() Lambda with a DOUBLE PRECISION return:
sql
SELECT (
toolkit_experimental.timevector(time, value)
-> toolkit_experimental.map($$ $value + 1 $$)
-> toolkit_experimental.unnest()).*
FROM (VALUES (TimestampTZ '2021-01-06 UTC', 0.0 ),
( '2021-01-01 UTC', 25.0 ),
( '2021-01-02 UTC', 0.10),
( '2021-01-04 UTC', -10.0 ),
( '2021-01-05 UTC', 3.3 )
) as v(time, value);The output for this example:
sql
time | value
------------------------+-------
2021-01-06 00:00:00+00 | 1
2021-01-01 00:00:00+00 | 26
2021-01-02 00:00:00+00 | 1.1
2021-01-04 00:00:00+00 | -9
2021-01-05 00:00:00+00 | 4.3
(5 rows)An example of the map() Lambda with a (TIMESTAMPTZ, DOUBLE PRECISION) return:
sql
SELECT (
toolkit_experimental.timevector(time, value)
-> toolkit_experimental.map($$ ($time + '1day'i, $value * 2) $$)
-> toolkit_experimental.unnest()).*
FROM (VALUES (TimestampTZ '2021-01-06 UTC', 0.0 ),
( '2021-01-01 UTC', 25.0 ),
( '2021-01-02 UTC', 0.10),
( '2021-01-04 UTC', -10.0 ),
( '2021-01-05 UTC', 3.3 )
) as v(time, value);The output for this example:
sql
time | value
------------------------+-------
2021-01-07 00:00:00+00 | 0
2021-01-02 00:00:00+00 | 50
2021-01-03 00:00:00+00 | 0.2
2021-01-05 00:00:00+00 | -20
2021-01-06 00:00:00+00 | 6.6
(5 rows)