---
name: "nsq-n2r"
section: "1"
platform: "linux"
package: "nosql"
version: "0.9-0"
release: "Debian 2.0 (Hamm)"
platforms: ["linux"]
url: "https://new.carta.tech/nosql"
---

# nsq-n2r(1)

Relational Database Management System

Part of [nosql(1)](/nosql/1.md).

## NAME

NoSQL - Relational Database Management System

## INTRODUCTION

NoSQL is a fast, portable, Relational DataBase Management System without arbitary limits, (other than memory and processor speed).

NoSQL uses the 'operator/stream' DBMS paradigm described in "Unix Review", March, 1991, page 24, entitled "A 4GL Language".  The operators are UNIX filters, i.e. they read STDIN and write STDOUT so they can be connected by pipes the ('\|' char).

The operators work with relational data in ascii files. The fields in each row are separated by a 'TAB' char and the row is terminated with a 'NEWLINE' char.  The first section of rows (the header) contains the names and data definitions for each column. The header also contains optional embedded documentation relating to the entire datafile and/or each data column. Subsequent rows (the body) contain the data values. A file in this form is said to be an 'rdbtable'. NoSQL is compliant with the 'Relational Model'.

These rdbtables are easily ported to and from spreadsheet programs on Macintoshes or MSDOS computers.

All operators read an rdbtable via STDIN and most write a new rdbtable via STDOUT. Exceptions are operators that produce output listings instead of rdbtables (like 'nsq-pr' and 'nsq-report').

All operators take a '-help' option to print usage detail and other information online.

## DESCRIPTION

Operators can be grouped into data movers, report generators, and utilities.

The data movers are operators that extract or rearrange the data in some way.  They each read an rdbtable via STDIN and write an rdbtable via STDOUT and so are frequently connected using the UNIX pipe function to form a larger task. Each operator in such a "pipeline" style of operation gets its input from the output of the previous operator in the "pipeline".  The data movers include:

- **nsq-col**

  Selects columns by name, outputs columns in listed order.

- **nsq-compute**

  Computes an arbitrary expression using column names.

- **nsq-headchg**

  Generates and replaces (or removes) the header of an rdbtable.

- **nsq-header**

  Extracts the header from an rdbtable.

- **nsq-join**

  Natural or "Master/Detail" join of two rdbtables.

- **nsq-l2t**

  Converts a file in *list* format to an rdbtable..

- **nsq-listtotable**

  Converts files from /rdb *list* to /rdb *table* format.

- **nsq-merge**

  Merges two like rdbtables.

- **nsq-n2r**

  Converts tables from NoSQL to /rdb format.

- **nsq-r2n**

  Converts tables from /rdb to NoSQL format.

- **nsq-row**

  Selects rows based on arbitrary Perl expressions.

- **nsq-search**

  Selects rows based on a multi-column key of a sorted or indexed rdbtable.

- **nsq-sort**

  Sorts a datafile by one or more columns.

- **nsq-subtot**

  Lists subtotals of specified columns.

- **nsq-t2l**

  Converts an rdbtable to *list* format.

- **nsq-tabletolist**

  Converts files from /rdb *table* to /rdb *list* format.

- **nsq-tee**

  Safely \[over\]writes an rdbtable.

- **nsq-uniq**

  Makes an rdbtable unique on specified columns.

The report generators each read an rdbtable via STDIN and produce a report on STDOUT, so when they are in a "pipeline" of operators they will be the operator at the end. The report generators are:

- **nsq-pr**

  Quick and easy printing of output formatted from information in the header.

- **nsq-report**

  Best form of output, with definable format.

- **nsq-summ**

  Summary/Statistical information about data values in an rdbtable.

- **nsq-valid**

  Verifies the structure of an rdbtable.

The utilities are used for manipulating the structure and content of rdbtables and are generally used as separate tasks, i.e. they do not read STDIN. The utilities are:

- **nsq**

  NoSQL interactive terminal interface.

- **nsq-ed**

  Uses an editor to allow modifications to an rdbtable.

- **nsq-index**

  Generate rdbtable index files to be used by *nsq-search*.

- **nsq-lock**

  Trivial table locking program, for serializing access to rdbtables.

- **nsq-mktbl**

  Makes a file of data in columns into an rdbtable.

- **nsq-repair**

  Attempts to repair candidate NoSQL datafiles.

- **nsq-updseq**

  Updates/Creates a unique record ID on each row of an rdbtable. The field must be the first column in the table.

All operators take a '**-h\[elp\]**' option to show details of operation online.

**Data Types:**

The type of data may be *string*, *numeric*, or *month*.  The types are specified by an **S**, **N**, or **M** respectively in the header. The default is type string.

## EXAMPLES

```
        # Embedded documentation for this rdbtable.
        # Any number of lines may exist.
        # Also available for each column (not shown here).
        NAME     CNT    TYP    AMT
        6        4N     3      5N
        Hobbs    65     DD     1111
        Bush     4      A      133
        Perry    177    B      244
        Jones    47     XY     77
        Hansen   44     A      23
The above rdbtable after being processed by the command:
nsq-col < sample NAME TYP AMT CNT | nsq-sort TYP AMT | nsq-pr
        NAME    TYP    AMT   CNT
        ------  ---  -----  ----
        Hansen  A       23    44
        Bush    A      133     4
        Perry   B      244   177
        Hobbs   DD    1111    65
        Jones   XY      77    47
```

## ENVIRONMENT

Environment variables used by NoSQL:

- **EDITOR**

  Used by the 'nsq-ed' utility (Default: 'vi').

- **PAGER**

  Used by the 'nsq' utility (Default: 'less').

- **TMPDIR**

  Where to store work files (Default: '/tmp').

- **NSQLOCKS**

  System-wide lock file directory (Default: table directory).

- **NSQLOCKER**

  Table locking program (Default: 'lockfile -r1').

- **NSQAWK**

  Name of the awk executable (Default: 'awk').

## HISTORY

As of this writing, NoSQL is mostly an RDB clone. The original RDB author is Walt Hobbs, of RAND Organization (E-mail: \<hobbs@rand.org\>). NoSQL uses exactly the same table format as RDB, and therefore tables are called 'rdbtables' also in the NoSQL context.

## AUTHOR

Carlo Strozzi \<carlos@linux.it\>

## BUGS

For the sake of speed, some operators should be rewritten in C.

The documentation is yet to be completed.
