All Products
Search
Document Center

Time Series Database:Data types and Cast operations

Last Updated:Aug 06, 2020

The SELECT clause allows you to use the :: syntax to specify the data type of a field and perform basic cast operations.

Data types

The data type of field values can be FLOAT, INTEGER, STRING, or BOOLEAN. The :: syntax allows you to specify the data type of field values in a query.

Notes: In most cases, you do not need to specify the data type of field values in the SELECT clause. In most cases, TSDB for InfluxDB® rejects the write requests that attempt to write field values to a field that previously stores the field values of a different data type. The data types of field values may be different across shard groups. In these cases, you may need to specify the data type of the field values in the SELECT clause.

Syntax

  1. SELECT_clause <field_key>::<type> FROM_clause

Description

The valid values of the type parameter are float, integer, string, and boolean. In most cases, if field_key does not store the data of the specified type, TSDB for InfluxDB® returns no data. For more information, see Cast operations.

Example

  1. > SELECT "water_level"::float FROM "h2o_feet" LIMIT 4
  2. name: h2o_feet
  3. --------------
  4. time water_level
  5. 2015-08-18T00:00:00Z 8.12
  6. 2015-08-18T00:00:00Z 2.064
  7. 2015-08-18T00:06:00Z 8.005
  8. 2015-08-18T00:06:00Z 2.116

The query returns the field values of the FLOAT data type for the water_level field key.

Cast operations

The :: syntax allows you to perform basic cast operations in queries. TSDB for InfluxDB® allows you to convert the data type of field values from INTEGER to FLOAT or from FLOAT to INTEGER.

Syntax

  1. SELECT_clause <field_key>::<type> FROM_clause

Description

In the syntax, the valid values of the type parameter are float and integer. If a query attempts to convert the data type of field values from INTEGER or FLOAT to STRING or BOOLEAN, TSDB for InfluxDB® returns no data.

Examples

Convert the data type of field values from FLOAT to INTEGER

  1. > SELECT "water_level"::integer FROM "h2o_feet" LIMIT 4
  2. name: h2o_feet
  3. --------------
  4. time water_level
  5. 2015-08-18T00:00:00Z 8
  6. 2015-08-18T00:00:00Z 2
  7. 2015-08-18T00:06:00Z 8
  8. 2015-08-18T00:06:00Z 2

The query casts the data type of the field values of water_level from FLOAT to INTEGER and returns the results.

Cast the data type of field values from FLOAT to STRING (not supported)

  1. > SELECT "water_level"::string FROM "h2o_feet" LIMIT 4
  2. >

The query returns no data because TSDB for InfluxDB® does not allow you to convert the data type of field values from FLOAT to STRING.


InfluxDB® is a trademark registered by InfluxData, which is not affiliated with, and does not endorse, TSDB for InfluxDB®.