murex Shell Docs

Optional Command Reference: select

Inlining SQL into shell pipelines

Description

select imports tabulated data into an in memory sqlite3 database and executes SQL queries against the data. It returns a table of the same data type as the input type

Usage

<stdin> -> select SQL -> <stdout>

Examples

List a count of all the processes running against each user ID:

» ps aux -> select count(*), user GROUP BY user ORDER BY 1
count(*) USER
1       _analyticsd
1       _applepay
1       _atsserver
1       _captiveagent
1       _cmiodalassistants
1       _ctkd
1       _datadetectors
1       _displaypolicyd
1       _distnote
1       _gamecontrollerd
1       _hidd
1       _iconservices
1       _installcoordinationd
1       _mdnsresponder
1       _netbios
1       _networkd
1       _reportmemoryexception
1       _timed
1       _usbmuxd
2       _appleevents
3       _assetcache
3       _fpsd
3       _nsurlsessiond
3       _softwareupdate
4       _windowserver
5       _coreaudiod
6       _spotlight
7       _locationd
144     root
308     foobar

Detail

Default Table Name

The table created is called main, however you do not need to include a FROM condition in your SQL as murex will inject FROM main into your SQL if it is missing. In fact, it is recommended that you exclude FROM from your SQL queries for the sake of brevity.

config Options

select's behavior is configurable:

» config -> [ select ]
{
    "fail-irregular-columns": {
        "Data-Type": "bool",
        "Default": false,
        "Description": "When importing a table into sqlite3, fail if there is an irregular number of columns",
        "Dynamic": false,
        "Global": false,
        "Value": false
    },
    "merge-trailing-columns": {
        "Data-Type": "bool",
        "Default": true,
        "Description": "When importing a table into sqlite3, if `fail-irregular-columns` is set to `false` and there are more columns than headings, then any additional columns are concatenated into the last column (space delimitated). If `merge-trailing-columns` is set to `false` then any trailing columns are ignored",
        "Dynamic": false,
        "Global": false,
        "Value": true
    },
    "print-headings": {
        "Data-Type": "bool",
        "Default": true,
        "Description": "Print headings when writing results",
        "Dynamic": false,
        "Global": false,
        "Value": true
    },
    "table-includes-headings": {
        "Data-Type": "bool",
        "Default": true,
        "Description": "When importing a table into sqlite3, treat the first row as headings (if `false`, headings are Excel style column references starting at `A`)",
        "Dynamic": false,
        "Global": false,
        "Value": true
    }
}

(See below for how to use config)

Read All vs Sequential Reads

At present, select only supports reading the entire table from STDIN before importing that data into sqlite3. There is some prototype code being written to support sequential imports but this is hugely experimental and not yet enabled.

This might make select unsuitable for large datasets.

Early Release

This is a very early release so there almost certainly will be bugs hiding. Which is another reason why this is currently only an optional builtin.

If you do run into any issues then please raise them on Github.

Synonyms

See Also

This site's content is rebuilt automatically from murex's source code after each merge to the master branch. Downloadable murex binaries are also built with the website.

Last built on Wed Jan 12 10:38:51 UTC 2022 against commit 50d6f4550d6f45b79e200b3cbc8e8e2639854a5265c7021.

Current version is 2.4.3010 BETA which has been verified against tests.