Miscellaneous SQL functions
The InfluxDB 3 Core SQL implementation supports the following miscellaneous functions
for performing a variety of operations:
arrow_cast
Casts a value to a specific Arrow data type.
arrow_cast(expression, datatype)
Arguments
- expression: Expression to cast.
Can be a constant, column, or function, and any combination of arithmetic or
string operators.
- datatype: Arrow data type
to cast to.
View arrow_cast
query example
The following example uses the sample data set provided in
Get started with InfluxDB tutorial.
SELECT
arrow_cast(time, 'Int64') AS time,
arrow_cast(temp, 'Utf8') AS temp,
arrow_cast(co, 'Float64')AS co
FROM home
LIMIT 1
time | temp | co |
---|
1641024000000000000 | 21.0 | 0 |
arrow_typeof
Returns the underlying Arrow data type
of the expression:
Arguments
- expression: Expression to evaluate.
Can be a constant, column, or function, and any combination of arithmetic or
string operators.
View arrow_typeof
query example
The following example uses the sample data set provided in
Get started with InfluxDB tutorial.
SELECT
arrow_typeof(time) AS time,
arrow_typeof(room) AS room,
arrow_typeof(temp) AS temp,
arrow_typeof(co) AS co
FROM home
LIMIT 1
time | room | temp | co |
---|
Timestamp(Nanosecond, None) | Dictionary(Int32, Utf8) | Float64 | Int64 |
get_field
Returns a field from a map or a struct with the specified key.
Typically, get_field
is indirectly invoked via field access syntax such as
my_struct['field_name']
which results in the call:
get_field(my_struct, 'field_name')
.
get_field(collection, field)
Arguments
- collection: The map or struct to retrieve a field from.
- field: The name of field the field to retrieve from the map or struct.
Must evaluate to a string.
View get_field
example with a struct column
SELECT
get_field(influxdb_struct, 'version') AS influxdb_version
FROM
(VALUES (struct('influxdb' AS product, 'v1' AS version)),
(struct('influxdb' AS product, 'v2' AS version)),
(struct('influxdb' AS product, 'v3' AS version))
) AS data(influxdb_struct)
View get_field
example with a map column
SELECT
get_field(influxdb_map, 'version') AS influxdb_version
FROM
(VALUES (map {'product': 'influxdb', 'version': 'v1'}),
(map {'product': 'influxdb', 'version': 'v2'}),
(map {'product': 'influxdb', 'version': 'v3'})
) AS data(influxdb_map)
interpolate
Fills null values in a specified aggregated column by interpolating values
from existing values.
Must be used with date_bin_gapfill
.
interpolate(aggregate_expression)
Arguments
- aggregate_expression: Aggregate operation on a specified expression.
The operation can use any aggregate function.
The expression can be a constant, column, or function, and any combination of
arithmetic operators supported by the aggregate function.
date_bin_gapfill,
locf
View interpolate
query example
The following example uses the sample data set provided in the
Get started with InfluxDB tutorial.
SELECT
date_bin_gapfill(INTERVAL '30 minutes', time) as _time,
room,
interpolate(avg(temp))
FROM home
WHERE
time >= '2022-01-01T08:00:00Z'
AND time <= '2022-01-01T10:00:00Z'
GROUP BY _time, room
_time | room | AVG(home.temp) |
---|
2022-01-01T08:00:00Z | Kitchen | 21 |
2022-01-01T08:30:00Z | Kitchen | 22 |
2022-01-01T09:00:00Z | Kitchen | 23 |
2022-01-01T09:30:00Z | Kitchen | 22.85 |
2022-01-01T10:00:00Z | Kitchen | 22.7 |
2022-01-01T08:00:00Z | Living Room | 21.1 |
2022-01-01T08:30:00Z | Living Room | 21.25 |
2022-01-01T09:00:00Z | Living Room | 21.4 |
2022-01-01T09:30:00Z | Living Room | 21.6 |
2022-01-01T10:00:00Z | Living Room | 21.8 |
locf
Fills null values in a specified aggregated column by carrying the last observed
value forward.
Must be used with date_bin_gapfill
.
LOCF is an initialism of “last observation carried forward.”
locf(aggregate_expression)
Arguments
- aggregate_expression: Aggregate operation on a specified expression.
The operation can use any aggregate function.
The expression can be a constant, column, or function, and any combination of
arithmetic operators supported by the aggregate function.
date_bin_gapfill,
interpolate
View locf
query example
The following example uses the sample data set provided in the
Get started with InfluxDB tutorial.
SELECT
date_bin_gapfill(INTERVAL '30 minutes', time) as _time,
room,
locf(avg(temp))
FROM home
WHERE
time >= '2022-01-01T08:00:00Z'
AND time <= '2022-01-01T10:00:00Z'
GROUP BY _time, room
_time | room | AVG(home.temp) |
---|
2022-01-01T08:00:00Z | Kitchen | 21 |
2022-01-01T08:30:00Z | Kitchen | 21 |
2022-01-01T09:00:00Z | Kitchen | 23 |
2022-01-01T09:30:00Z | Kitchen | 23 |
2022-01-01T10:00:00Z | Kitchen | 22.7 |
2022-01-01T08:00:00Z | Living Room | 21.1 |
2022-01-01T08:30:00Z | Living Room | 21.1 |
2022-01-01T09:00:00Z | Living Room | 21.4 |
2022-01-01T09:30:00Z | Living Room | 21.4 |
2022-01-01T10:00:00Z | Living Room | 21.8 |
version
Returns the version of DataFusion.
Was this page helpful?
Thank you for your feedback!
Support and feedback
Thank you for being part of our community!
We welcome and encourage your feedback and bug reports for InfluxDB 3 Core and this documentation.
To find support, use the following resources:
Customers with an annual or support contract can contact InfluxData Support.