Spec-Zone.ru › Nushell

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
record record
table table
list<any> list<any>

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 new column with values computed based off the other columns

> [[foo]; [7] [8] [9]] | insert bar {|row| $row.foo * 2 }
╭───┬─────┬─────╮
│ # │ foo │ bar │
├───┼─────┼─────┤
│ 0 │   7 │  14 │
│ 1 │   8 │  16 │
│ 2 │   9 │  18 │
╰───┴─────┴─────╯

Insert a new value into a list at an index

> [1 2 4] | insert 2 3
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
╰───┴───╯

Insert a new value at the end of a list

> [1 2 3] | insert 3 4
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
╰───┴───╯

Insert into a nested path, creating new values as needed

> [{} {a: [{}]}] | insert a.0.b "value"
╭───┬───────────────────────────╮
│ # │             a             │
├───┼───────────────────────────┤
│ 0 │ ╭───┬───────╮             │
│   │ │ b │ value │             │
│   │ ╰───┴───────╯             │
│ 1 │ ╭───┬───────────────────╮ │
│   │ │ 0 │ {record 0 fields} │ │
│   │ ╰───┴───────────────────╯ │
╰───┴───────────────────────────╯

Notes

When inserting a column, the closure will be run for each row, and the current row will be passed as the first argument. When inserting into a specific index, the closure will instead get the current value at the index or null if inserting at the end of a list/table.

Copyright © 2019–2026 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/insert.html

Spec-Zone.ru

Настройки Оффлайн Что нового Помощь О нас
Spec-Zone .ru
спецификации, руководства, описания, API