123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- [discrete]
- [[esql-eval]]
- === `EVAL`
- The `EVAL` processing command enables you to append new columns with calculated
- values.
- **Syntax**
- [source,esql]
- ----
- EVAL [column1 =] value1[, ..., [columnN =] valueN]
- ----
- *Parameters*
- `columnX`::
- The column name.
- If a column with the same name already exists, the existing column is dropped.
- If a column name is used more than once, only the rightmost duplicate creates a column.
- `valueX`::
- The value for the column. Can be a literal, an expression, or a
- <<esql-functions,function>>. Can use columns defined left of this one.
- *Description*
- The `EVAL` processing command enables you to append new columns with calculated
- values. `EVAL` supports various functions for calculating values. Refer to
- <<esql-functions,Functions>> for more information.
- *Examples*
- [source.merge.styled,esql]
- ----
- include::{esql-specs}/eval.csv-spec[tag=eval]
- ----
- [%header.monospaced.styled,format=dsv,separator=|]
- |===
- include::{esql-specs}/eval.csv-spec[tag=eval-result]
- |===
- If the specified column already exists, the existing column will be dropped, and
- the new column will be appended to the table:
- [source.merge.styled,esql]
- ----
- include::{esql-specs}/eval.csv-spec[tag=evalReplace]
- ----
- [%header.monospaced.styled,format=dsv,separator=|]
- |===
- include::{esql-specs}/eval.csv-spec[tag=evalReplace-result]
- |===
- Specifying the output column name is optional. If not specified, the new column
- name is equal to the expression. The following query adds a column named
- `height*3.281`:
- [source.merge.styled,esql]
- ----
- include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumn]
- ----
- [%header.monospaced.styled,format=dsv,separator=|]
- |===
- include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumn-result]
- |===
- Because this name contains special characters, <<esql-identifiers,it needs to be
- quoted>> with backticks (+{backtick}+) when using it in subsequent commands:
- [source.merge.styled,esql]
- ----
- include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumnStats]
- ----
- [%header.monospaced.styled,format=dsv,separator=|]
- |===
- include::{esql-specs}/eval.csv-spec[tag=evalUnnamedColumnStats-result]
- |===
|