Skip to content

locf()

Fill in missing values by carrying the last observed value forward

Since 1.1.1

Fill in missing values by carrying the last observed value forward. Use in the same query as time_bucket_gapfill. locf cannot be nested inside another function call.

The syntax is:

SELECT locf(
value = <anyelement>,
prev = <anyelement>,
treat_null_as_missing = true | false
);
NameTypeDefaultRequiredDescription
valueANY ELEMENT-The value to carry forward
prevEXPRESSION--If no previous value is available for gapfilling, use the prev lookup expression to get a previous value. For example, you can use prev to fill in the first bucket in a queried time range. The expression must return just a value (not a tuple as expected by the interpolate function) with the same type as the value parameter.
treat_null_as_missingBOOLEAN--When true, NULL values are ignored, and only non-NULL values are carried forward.
ColumnTypeDescription
locfANY ELEMENTThe gapfilled value. The return type matches the input value type.