Back to Elasticsearch

Eval

docs/reference/query-languages/esql/_snippets/commands/layout/eval.md

9.4.01.9 KB
Original Source
yaml
serverless: ga
stack: ga

The EVAL processing command enables you to append new columns with calculated values.

Syntax

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 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 Functions for more information.

Examples

The following examples show common EVAL patterns.

Append a calculated column

:::{include} ../examples/eval.csv-spec/eval.md :::

Overwrite an existing column

If the specified column already exists, the existing column will be dropped, and the new column will be appended to the table:

:::{include} ../examples/eval.csv-spec/evalReplace.md :::

Use an expression as the column name

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:

:::{include} ../examples/eval.csv-spec/evalUnnamedColumn.md :::

Reference an auto-named column in a subsequent command

Because this name contains special characters, it needs to be quoted with backticks (```) when using it in subsequent commands:

:::{include} ../examples/eval.csv-spec/evalUnnamedColumnStats.md :::