From 15e18ee1d66f82d7ac13705997f7fb6953dfe549 Mon Sep 17 00:00:00 2001 From: Tyler Brinkman Date: Sun, 12 Jan 2025 00:33:44 -0600 Subject: [PATCH] Describe difference between `get` and `select` --- lang-guide/chapters/filters/select-get.md | 32 ++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lang-guide/chapters/filters/select-get.md b/lang-guide/chapters/filters/select-get.md index 746d61ee0d7..6fd6a6a2cf2 100644 --- a/lang-guide/chapters/filters/select-get.md +++ b/lang-guide/chapters/filters/select-get.md @@ -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. + +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 +```