insert for filters

Insert a new column, using an expression or closure to create each row's values.

Signature

> insert {flags} (field) (new value)

Parameters

  • field: the name of the column to insert
  • new value: the new value to give the cell(s)

Input/output types:

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

Examples

Insert a new entry into a single record

> {'name': 'rsh', 'stars': 5} | insert alias 'rsh'
╭───────┬─────────╮
│ name  │ rsh      │
│ stars │ 5       │
│ alias │ rsh │
╰───────┴─────────╯

Insert a new column into a table, populating all rows

> [[project, lang]; ['rsh', 'Rust']] | insert type 'shell'
╭───┬─────────┬──────┬───────╮
│ # │ project │ lang │ type  │
├───┼─────────┼──────┼───────┤
│ 0 │ rsh │ Rust │ shell │
╰───┴─────────┴──────┴───────╯

Insert a column with values equal to their row index, plus the value of 'foo' in each row

> [[foo]; [7] [8] [9]] | enumerate | insert bar {|e| $e.item.foo + $e.index } | flatten
╭───┬─────┬─────╮
│ # │ foo │ bar │
├───┼─────┼─────┤
│ 0 │   7 │   7 │
│ 1 │   8 │   9 │
│ 2 │   9 │  11 │
╰───┴─────┴─────╯