Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 31 additions & 1 deletion lang-guide/chapters/filters/select-get.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,33 @@
# Understanding the difference between `get` and `select`

TODO
### Get

Extract data using a cell path.

This is equivalent to using the cell path access syntax: `$env.OS` is the same as `$env | get OS`.

If multiple cell paths are given, this will produce a list of values.

```nu
'{"name":"Alice","job":"Engineer"}'
| from json
| get name
| describe
# => string
```

### Select

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

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.
Copy link
Contributor

@fdncred fdncred Jan 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This statement is a little confusing. I always thought of get and select like this.

  • get gets the value out of the structure it is in
  • select selects the value maintaining the structure it is in

I'm not saying you have to use my words, but it would be better to say it a little differently than it currently is here.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I just grabbed the language from the implementation, scope commands | where name == select | get extra_description.0. I didn't realize it was already documented in the Book, so I will close this PR.


Hence, using `select` on a table will produce a table, a list will produce a list, and a record will produce a record.

```nu
'{"name":"Alice","job":"Engineer"}'
| from json
| select name
| describe
# => record<name: string>
```