Nushell
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
Get Nu!
Getting Started
  • The Nushell Book
  • Command Reference
  • Cookbook
  • Language Reference Guide
  • Contributing Guide
Blog
  • English
  • 中文
  • Deutsch
  • Français
  • Español
  • 日本語
  • Português do Brasil
  • Русский язык
GitHub
  • Language Reference Guide
    • Readme
    • Types in the Nu Language
      • Basic Types
        • Any
        • Boolean
        • Integer
        • Float
        • Filesize
        • Duration
        • Datetime
        • Range
        • String
        • Record
        • List
        • Table
        • Closure
        • Nothing
        • Binary
        • Glob
        • Cell-Path
      • Other Data Types

        • Types that cannot be used to declare variables
          • Path
        • Types which are not declarable
          • Error
          • CustomValue
          • Block
      • Type signatures
      • Commands that interact with types
    • Operators
    • Flow control
      • if/else
      • loop
      • while
      • match
      • try/catch
      • break
      • return
      • continue
    • Filters
      • each and par-each
      • Filters to select subsets of data
      • where and filter
      • Understanding the difference between get and select
    • Custom Commands
    • Declarations
    • Variable Scope
    • Strings and Text Formatting
    • Helpers and debugging commands
    • Pipelines
    • MIME Types for Nushell

Table

Description:A two-dimensional container with both columns and rows where each cell can hold any basic or structured data type
Annotation:table
Table-Literal Syntax:See below
Casts:wrap
See Also:Working with Tables
Navigating and Accessing Structured Data
Types of Data - Tables

Creating Tables

Table-literal syntax

Table literals can be created using a syntax similar to that of a list literal. Because tables also contain columns and not just values, we also specify the column names:

[[column1, column2]; [Value1, Value2] [Value3, Value4]]
# => ╭───┬─────────┬─────────╮
# => │ # │ column1 │ column2 │
# => ├───┼─────────┼─────────┤
# => │ 0 │ Value1  │ Value2  │
# => │ 1 │ Value3  │ Value4  │
# => ╰───┴─────────┴─────────╯

In this syntax, the headers are separated from the data cells using a semicolon(;). The semicolon separator is mandatory in a table-literal. It must follow the headers.

List-of-Records syntax

You can also create a table as a list of records, JSON-style:

[{name: "Sam", rank: 10}, {name: "Bob", rank: 7}]
# => ╭───┬──────┬──────╮
# => │ # │ name │ rank │
# => ├───┼──────┼──────┤
# => │ 0 │ Sam  │   10 │
# => │ 1 │ Bob  │    7 │
# => ╰───┴──────┴──────╯

This list-of-records pattern plays on the Nushell data model, which sees a list of records as equivalent to a table. This is useful in cases where the length of a table may not be known ahead of time. In such a case, a stream of records likewise represents a table.

Common commands that can be used with table

  • table
  • ls
  • ps
  • sys
  • select
  • get
  • where
  • range

Note

Most of Nushell's filter commands work with tables. For a longer list see: help commands | where category == filters.

Edit this page on GitHub
Contributors: NotTheDr01ds, fdncred, 0x4D5352
Prev
List
Next
Closure