Output Formats
Choose how MariaDB Shell prints query results: table, tabbed, vertical, JSON, and newline-delimited JSON, with column type information and result formatting from Python.
MariaDB Shell prints query results in one of several formats. Tables suit reading at the prompt, tab-separated output suits shell pipelines, and JSON suits programs that consume the results.
Available Formats
table
Rows in a grid framed with ASCII characters. The default in interactive sessions.
tabbed
A header line and one line per row, with values separated by tabs and no frame. The default in batch mode.
vertical
Each row as a block, with one column: value line per column.
json
Same as json/pretty.
json/pretty
Each row as an indented JSON object.
ndjson
Same as json/raw.
json/raw
Each row as a compact JSON object on one line (newline-delimited JSON).
json/array
Compact JSON objects, one per line, enclosed in a JSON array.
Choosing the Format
--result-format=<format>
The whole session. Accepts all formats in the table above.
--table
Same as --result-format=table. Use it to get tables in batch mode.
--tabbed
Same as --result-format=tabbed. Use it to get tab-separated output in an interactive session.
-E, --vertical
Same as --result-format=vertical.
--json[=pretty|raw|off]
Wraps all shell output in JSON documents. See JSON Output for Programs.
resultFormat option
Changes the format during the session with \option resultFormat <format>, or persists it with \option --persist resultFormat <format>.
\G terminator
Prints the result of one statement vertically, or in another format with a suffix. See Format for One Statement.
If you don't choose a format, the shell uses table when it runs interactively and tabbed in batch mode. A format that you set explicitly applies in both.
Format for One Statement
In SQL mode, the \G terminator selects a format for a single statement without changing the resultFormat option. On its own, \G prints the result vertically. A letter after it selects another format:
\G
Vertical.
\Gj
A JSON array with one object per row.
\GJ
A JSON document with the rows and the result metadata, as described in JSON Output for Programs.
\GT
Tab-separated values with a header line.
\Gt
Tab-separated values without a header line.
The terminators work in interactive and batch mode. \GT and \Gt have no effect when the shell runs with --json.
Examples
The examples use the following query on a small customer table.
Numbers are right-aligned, other values left-aligned.
In batch mode, the row count line isn't printed.
The output is a sequence of JSON objects, not a single JSON document.
The output of each statement is one valid JSON document.
Value Conversion in JSON Formats
In the JSON formats, the shell maps column values to JSON types:
Integer types
Number
FLOAT, DOUBLE
Number
DECIMAL
Number, with all the digits of the value, such as 24.90
NULL
null
JSON
The JSON value itself, embedded as object or array.
Date and time types
String, such as "2026-01-12" or "2026-01-01 10:00:00"
Binary types (BINARY, VARBINARY, BLOB)
Base64-encoded string
Other types
String
JSON Output for Programs
--json goes further than --result-format=json: it turns all output of the shell into JSON, including messages, warnings, errors, and text printed by Python code. Each item is a separate JSON document. A program that runs the shell can then parse everything it reads from standard output.
--json or --json=pretty
Indented JSON documents.
--json=raw
One compact JSON document per line.
--json=off
Normal output.
For an SQL statement, the document describes the whole result:
hasData
true if the statement returned a result set.
rows
The rows, as JSON objects.
executionTime
The execution time.
affectedItemsCount
Rows changed by a DML statement.
warningsCount, warnings
The number of warnings and the warnings themselves.
info
The server's information string, such as Rows matched: 3 Changed: 0 Warnings: 0.
autoIncrementValue
The AUTO_INCREMENT value generated by an INSERT.
Other output has its own documents, keyed by type:
Column Type Information
--column-type-info prints the metadata of each result column before the result, in SQL mode. Use it to check how the server types an expression, or which collation a column uses. The option showColumnTypeInfo does the same and can be changed during the session.
Name and Table show the names as they appear in the result, which can be aliases. Org_name and Org_table show the underlying column and table. Type is the shell's type name and DbType the protocol type the server reported.
In Python, the same metadata is available from the columns property of a result. See SQL and Python Modes.
Formatting Results in Python
shell.dump_rows(result[, format]) prints a result object from session.run_sql() in any of the formats above and returns the number of rows it printed. Without a format, it uses table, regardless of the resultFormat option:
dump_rows() reads the rows from the result, so you can't fetch them again afterward. Use it in reports and scripts that print query results:
This page is licensed: GPLv2
Last updated
Was this helpful?

