to_integer.asciidoc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. [discrete]
  2. [[esql-to_integer]]
  3. === `TO_INTEGER`
  4. *Alias*
  5. `TO_INT`
  6. *Syntax*
  7. [source,esql]
  8. ----
  9. TO_INTEGER(v)
  10. ----
  11. *Parameters*
  12. `v`::
  13. Input value. The input can be a single- or multi-valued column or an expression.
  14. *Description*
  15. Converts an input value to an integer value.
  16. If the input parameter is of a date type, its value will be interpreted as
  17. milliseconds since the {wikipedia}/Unix_time[Unix epoch], converted to integer.
  18. Boolean *true* will be converted to integer *1*, *false* to *0*.
  19. *Supported types*
  20. The input type must be of a boolean, date, string or numeric type.
  21. *Example*
  22. [source.merge.styled,esql]
  23. ----
  24. include::{esql-specs}/ints.csv-spec[tag=to_int-long]
  25. ----
  26. [%header.monospaced.styled,format=dsv,separator=|]
  27. |===
  28. include::{esql-specs}/ints.csv-spec[tag=to_int-long-result]
  29. |===
  30. Note that in this example, the last value of the multi-valued field cannot
  31. be converted as an integer. When this happens, the result is a *null* value.
  32. In this case a _Warning_ header is added to the response. The header will
  33. provide information on the source of the failure:
  34. `"Line 1:61: evaluation of [TO_INTEGER(long)] failed, treating result as null. Only first 20 failures recorded."`
  35. A following header will contain the failure reason and the offending value:
  36. `"org.elasticsearch.xpack.ql.InvalidArgumentException: [501379200000] out of [integer] range"`