select

Synopsis

any |> select <fields>...

Description

select keeps the named fields of each record, in the order written, and adds computed fields written as name: expression. A field path such as owner.name reads a field inside another field and is named after its last segment.

Records that only keep top-level fields keep their record kind. Records with a computed field, or with a field read from inside another field, become map records. A field the record does not have stops the program with E_UNKNOWN_FIELD, which lists the fields of the record.

The stage is lazy and keeps the header of the stream. The order declared by the source and its presentation hint are dropped, because they may name fields that are no longer present. An empty input gives an empty output.

Parameters

Parameter Type Default Description
fields list<field | named_expression> required Fields to keep and name: expression pairs to compute.

Input and output

Form Input Output
default any any

Effect

Property Value
Category transform
Effect read
Reversibility read
Implementation builtin

Examples

Keep the path and the size of each file:

find "/home/user/project" |> select path size

Add a computed field that marks large files:

find "/home/user/project" |> select path large: size > 2kb

Keep the exit code and the output of a program run:

run ["git", "status", "--short"] cwd: "/home/user/project" |> select exit_code stdout

Errors

Code Meaning Typical fix
E_MISSING_PARAM no field is given name at least one field
E_UNKNOWN_FIELD a field is not in the record; expected lists the fields use one of the listed fields
E_TYPE an item is neither a field nor name: expression write a field name or name: expression

filter, sort, distinct, describe.

Source file on GitHub: docs/commands/select.md