select for filters

Select only these columns or rows from the input. Opposite of `reject`.

Signature

> select {flags} ...rest

Flags

  • --ignore-errors, -i: ignore missing data (make all cell path members optional)

Parameters

  • ...rest: The columns to select from the table.

Input/output types:

inputoutput
list<any>any
recordrecord
tabletable

Examples

Select a column in a table

> [{a: a b: b}] | select a
╭───┬───╮
 # │ a │
├───┼───┤
 0  a 
╰───┴───╯

Select a field in a record

> {a: a b: b} | select a
╭───┬───╮
 a  a 
╰───┴───╯

Select just the name column

> ls | select name

Select the first four rows (this is the same as first 4)

> ls | select 0 1 2 3

Select columns by a provided list of columns

> let cols = [name type];[[name type size]; [Cargo.toml toml 1kb] [Cargo.lock toml 2kb]] | select $cols

Select columns by a provided list of columns

> [[name type size]; [Cargo.toml toml 1kb] [Cargo.lock toml 2kb]] | select ["name", "type"]
╭───┬────────────┬──────╮
 # │    name    │ type │
├───┼────────────┼──────┤
 0  Cargo.toml  toml 
 1  Cargo.lock  toml 
╰───┴────────────┴──────╯

Select rows by a provided list of rows

> let rows = [0 2];[[name type size]; [Cargo.toml toml 1kb] [Cargo.lock toml 2kb] [file.json json 3kb]] | select $rows

Notes

This differs from get in that, rather than accessing the given value in the data structure, it removes all non-selected values from the structure. Hence, using select on a table will produce a table, a list will produce a list, and a record will produce a record.