insert for filters

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

Signature

> insert (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:

inputoutput
list<any>list<any>
recordrecord
tabletable

Examples

Insert a new entry into a single record

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

Insert a new column into a table, populating all rows

> [[project, lang]; ['Nushell', 'Rust']] | insert type 'shell'
╭───┬─────────┬──────┬───────╮
│ # │ project │ lang │ type  │
├───┼─────────┼──────┼───────┤
│ 0 │ Nushell │ 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 │
├───┼─────┼─────┤
│ 077 │
│ 189 │
│ 2911 │
╰───┴─────┴─────╯