eval.asciidoc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. [discrete]
  2. [[esql-eval]]
  3. === `EVAL`
  4. **Syntax**
  5. [source,esql]
  6. ----
  7. EVAL [column1 =] value1[, ..., [columnN =] valueN]
  8. ----
  9. *Parameters*
  10. `columnX`::
  11. The column name.
  12. `valueX`::
  13. The value for the column. Can be a literal, an expression, or a
  14. <<esql-functions,function>>.
  15. *Description*
  16. The `EVAL` processing command enables you to append new columns with calculated
  17. values. `EVAL` supports various functions for calculating values. Refer to
  18. <<esql-functions,Functions>> for more information.
  19. *Examples*
  20. [source.merge.styled,esql]
  21. ----
  22. include::{esql-specs}/eval.csv-spec[tag=eval]
  23. ----
  24. [%header.monospaced.styled,format=dsv,separator=|]
  25. |===
  26. include::{esql-specs}/eval.csv-spec[tag=eval-result]
  27. |===
  28. If the specified column already exists, the existing column will be dropped, and
  29. the new column will be appended to the table:
  30. [source.merge.styled,esql]
  31. ----
  32. include::{esql-specs}/eval.csv-spec[tag=evalReplace]
  33. ----
  34. [%header.monospaced.styled,format=dsv,separator=|]
  35. |===
  36. include::{esql-specs}/eval.csv-spec[tag=evalReplace-result]
  37. |===
  38. Specifying the output column name is optional. If not specified, the new column
  39. name is equal to the expression. The following query adds a column named
  40. `height*3.281`:
  41. [source.merge.styled,esql]
  42. ----
  43. include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumn]
  44. ----
  45. [%header.monospaced.styled,format=dsv,separator=|]
  46. |===
  47. include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumn-result]
  48. |===
  49. Because this name contains special characters, <<esql-identifiers,it needs to be
  50. quoted>> with backticks (+{backtick}+) when using it in subsequent commands:
  51. [source.merge.styled,esql]
  52. ----
  53. include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumnStats]
  54. ----
  55. [%header.monospaced.styled,format=dsv,separator=|]
  56. |===
  57. include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumnStats-result]
  58. |===