Switching to Markdown Mode in DuckDB

This article shows you how to output your DuckDB query results in Markdown table format when using the DuckDB command line interface (CLI). This can be useful when creating documentation or preparing content for platforms that support Markdown.

Checking the Current Mode

There are two ways to check your current output mode:

The easiest way to check your current output mode is by using the .mode command:

.mode

Sample output:

current output mode: json

My current output mode is json.

Another way to check the current output mode is by running a sample query to see the output format:

CREATE TABLE books(id INTEGER, title VARCHAR, author VARCHAR, price DECIMAL);
INSERT INTO books VALUES 
    (1, 'The Great Gatsby', 'F. Scott Fitzgerald', 15.99),
    (2, '1984', 'George Orwell', 12.99);
SELECT * FROM books;

Output:

[{"id":1,"title":"The Great Gatsby","author":"F. Scott Fitzgerald","price":15.990},
{"id":2,"title":"1984","author":"George Orwell","price":12.990}]

We can see that it returned the results in a JSON document.

Changing to Markdown Mode

To switch to Markdown output mode, use:

.mode markdown

Verifying the Change

Check the mode setting:

.mode

This will confirm that Markdown mode is active:

current output mode: markdown

Now let’s run a query to see the Markdown table output:

SELECT * FROM books;

The output will now be formatted as a Markdown table:

| id |      title       |       author        | price  |
|---:|------------------|---------------------|-------:|
| 1 | The Great Gatsby | F. Scott Fitzgerald | 15.990 |
| 2 | 1984 | George Orwell | 12.990 |

When rendered, this creates a properly formatted table in any Markdown-compatible viewer.

Reverting to the Previous Mode

To return to the JSON output mode:

.mode json

You don’t have to revert to the previous mode, of course. You could change to any mode you like, or keep it in Markdown mode.

Listing All Available Output Modes

To see all available output modes in DuckDB CLI:

.help mode

Output:

.mode MODE ?TABLE?       Set output mode
MODE is one of:
ascii Columns/rows delimited by 0x1F and 0x1E
box Tables using unicode box-drawing characters
csv Comma-separated values
column Output in columns. (See .width)
duckbox Tables with extensive features
html HTML <table> code
insert SQL insert statements for TABLE
json Results in a JSON array
jsonlines Results in a NDJSON
latex LaTeX tabular environment code
line One value per line
list Values delimited by "|"
markdown Markdown table format
quote Escape answers as for SQL
table ASCII-art table
tabs Tab-separated values
tcl TCL list elements
trash No output

Each mode has its own use cases, for example:

  • html for web integration
  • csv for spreadsheet compatibility
  • json for API responses
  • insert for generating SQL INSERT statements
  • ndjson for streaming data processing

The Markdown mode is particularly useful when:

  • Writing technical documentation
  • Creating GitHub README files
  • Preparing content for wikis
  • Making data tables for blog posts
  • Sharing query results in platforms that support Markdown (like GitHub, GitLab, or Confluence)
  • Creating readable tables that can be easily converted to other formats