Skip to main content

serened shell

serened shell is a local, embedded SQL shell built into the serened binary. It runs queries directly against a DuckDB database file — or an in-memory database — without starting a server or opening a network connection. It is handy for ad-hoc queries, exploring data files (CSV, Parquet, DuckDB), scripting, and formatting SQL.

To connect to a running SereneDB server instead, use serened psql.

Usage

serened shell [OPTION]... [FILENAME [SQL]]

FILENAME is the path to a DuckDB database file; a new file is created if it does not exist. Omit it (or pass :memory:) for an in-memory database. The optional SQL argument is run before the interactive prompt starts.

Open an in-memory shell:

serened shell

Open a database file:

serened shell my_data.db

Running a single command

Use -c to run one statement and exit:

serened shell :memory: -c "SELECT 1 + 1 AS sum;"
┌───────┐
│ sum │
│ int32 │
├───────┤
│ 2 │
└───────┘

Querying data files

The shell reads files directly through table functions such as read_csv and read_parquet:

serened shell :memory: -c "SELECT * FROM read_csv('data.csv');"
┌───────┬─────────┐
│ id │ name │
│ int64 │ varchar │
├───────┼─────────┤
│ 1 │ alpha │
│ 2 │ beta │
└───────┴─────────┘

You can also pipe a script via standard input:

echo "SELECT 'piped' AS src;" | serened shell

Creating objects

Unlike a server connection, the shell does not pre-select a default database. To create objects, first select a database with USE (or fully-qualify the name), otherwise SereneDB reports Catalog Error: no schema has been selected to create in:

serened shell :memory: -c "USE memory; CREATE TABLE t (i INTEGER); INSERT INTO t VALUES (1), (2); SELECT count(*) AS rows FROM t;"
┌───────┐
│ rows │
│ int64 │
├───────┤
│ 2 │
└───────┘

Output modes

The default output is the aligned duckbox table. Switch modes with a --MODE flag (box, csv, json, markdown, line, …) or with -P format=…:

serened shell :memory: --markdown -c "SELECT 1 AS a, 2 AS b;"
| a | b |
|--:|--:|
| 1 | 2 |

Formatting SQL

--format pretty-prints SQL read from standard input (use --format-file for a file):

echo "select a,b from t where a>1 order by b" | serened shell --format
SELECT a, b
FROM t
WHERE a > 1
ORDER BY b

Options

General options

OptionDescription
-c, --command=COMMANDRun a single command (SQL or dot-command) and exit
-s COMMANDAlias for -c
-f, --file=FILENAMEExecute commands from a file, then exit
--cmd=COMMANDRun a command before reading stdin (does not exit)
--init=FILENAMEPre-initialize from a file (overrides the default ~/.duckdbrc)
-X, --no-initDo not read the startup file
--bailStop after hitting an error
-1, --single-transactionWrap the -c / -f batch in BEGIN / COMMIT
--formatFormat SQL from stdin and write the result to stdout
--format-file=FILENAMEFormat SQL in a file and write the result to stdout
-V, --versionPrint the SereneDB version and exit
-?, --helpShow the help message and exit

Input and output options

OptionDescription
-a, --echo-allEcho all input from the script
-e, --echo-queriesEcho commands before execution
-o, --output=FILENAMESend query results to a file
-q, --quietSuppress informational messages
--interactiveForce interactive input
--batchForce batch input
--no-stdinExit after processing options instead of reading stdin

Output format options

OptionDescription
-A, --no-alignUnaligned output
--csvCSV output
-H, --htmlHTML output
-t, --tuples-onlyPrint rows only, without column headers
-x, --expandedExpanded output (one value per line)
-F, --field-separator=STRField separator for unaligned output (default |)
--nullvalue=TEXTText shown for NULL values (default NULL)
--MODESet the output mode directly (box, csv, json, markdown, line, …)

Database options

OptionDescription
--readonlyOpen the database read-only
--safeEnable safe-mode
--storage-version=VERStorage compatibility version for new database files
--unsignedAllow loading unsigned extensions
--uiLaunch a web interface via the ui extension
note

The flags -h, -l and -s differ from serened psql: in the shell, -h shows the help message, -l selects list output mode, and -s is an alias for -c.