Skip to content

Latest commit

 

History

History
118 lines (91 loc) · 3.15 KB

select.md

File metadata and controls

118 lines (91 loc) · 3.15 KB
title select
categories filters
version 0.116.0
filters Select only these columns or rows from the input. Opposite of `reject`.
usage Select only these columns or rows from the input. Opposite of `reject`.
editLink false
contributors false

select for filters

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

Command Type

built-in

Signature

> select {flags} ...rest

Flags

  • --optional, -o: Make all cell path members optional (returns null for missing values).
  • --ignore-case: Make all cell path members case insensitive.
  • --ignore-errors, -i: Ignore missing data (make all cell path members optional) (deprecated).

Parameters

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

Input/output types:

input output
record record
table table
list<any> any
SQLiteQueryBuilder SQLiteQueryBuilder

Examples

Select a column in a table.

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

Select a column even if some rows are missing that column.

> [{a: a0 b: b0} {b: b1}] | select -o a
╭───┬────╮
│ # │ a  │
├───┼────┤
│ 0 │ a0 │
│ 1 │    │
╰───┴────╯

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 multiple 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 multiple columns by spreading a list.

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

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.