to_double.asciidoc 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. [discrete]
  2. [[esql-to_double]]
  3. === `TO_DOUBLE`
  4. *Alias*
  5. `TO_DBL`
  6. *Syntax*
  7. [source,esql]
  8. ----
  9. TO_DOUBLE(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 a double 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 double.
  18. Boolean *true* will be converted to double *1.0*, *false* to *0.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}/floats.csv-spec[tag=to_double-str]
  25. ----
  26. [%header.monospaced.styled,format=dsv,separator=|]
  27. |===
  28. include::{esql-specs}/floats.csv-spec[tag=to_double-str-result]
  29. |===
  30. Note that in this example, the last conversion of the string isn't possible.
  31. When this happens, the result is a *null* value. In this case a _Warning_ header
  32. is added to the response. The header will provide information on the source of
  33. the failure:
  34. `"Line 1:115: evaluation of [TO_DOUBLE(str2)] failed, treating result as null. Only first 20 failures recorded."`
  35. A following header will contain the failure reason and the offending value:
  36. `"java.lang.NumberFormatException: For input string: \"foo\""`