eval.asciidoc 2.1 KB

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