Home Explore Blog CI



nushell

1st chunk of `commands/docs/insert.md`
b8dd217a84df6d0daeacb6e20e5a4e5368f0254e6f4cd0650000000100000df0
---
title: insert
categories: |
  filters
version: 0.104.0
filters: |
  Insert a new column, using an expression or closure to create each row's values.
usage: |
  Insert a new column, using an expression or closure to create each row's values.
editLink: false
contributors: false
---
<!-- This file is automatically generated. Please edit the command in https://github.com/nushell/nushell instead. -->

# `insert` for [filters](/commands/categories/filters.md)

<div class='command-title'>Insert a new column, using an expression or closure to create each row&#x27;s values.</div>

## 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
```nu
> {'name': 'nu', 'stars': 5} | insert alias 'Nushell'
╭───────┬─────────╮
│ name  │ nu      │
│ stars │ 5       │
│ alias │ Nushell │
╰───────┴─────────╯
```

Insert a new column into a table, populating all rows
```nu
> [[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
```nu
> [[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
```nu
> [1 2 4] | insert 2 3
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
╰───┴───╯

```

Insert a new value at the end of a list
```nu
> [1 2 3] | insert 3 4
╭───┬───╮
│ 0 │ 1 │
│ 1 │ 2 │
│ 2 │ 3 │
│ 3 │ 4 │
╰───┴───╯

```

Insert into a nested path, creating new values as needed
```nu
> [{} {a: [{}]}] | insert a.0.b "value"
╭───┬───────────────╮
│ # │       a       │
├───┼───────────────┤
│ 0 │ ╭───┬───────╮ │
│   │ │ # │   b   │ │
│   │ ├───┼───────┤ │
│   │ │ 0 │ value │ │
│   │ ╰───┴───────╯ │
│ 1 │ ╭───┬───────╮ │
│   │ │ # │   b   │ │
│   │ ├───┼───────┤ │
│   │ │ 0 │ value │ │
│   │ ╰───┴───────╯ │
╰───┴───────────────╯

```

## 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.

Title: insert
Summary
The `insert` command in Nushell is used to add a new column to a record or table, or insert a new element into a list. It takes the field name (or index), and the new value as arguments. The new value can be a fixed value, or computed from a closure. 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.