Suppressing Query Output in the DuckDB CLI

DuckDB’s command-line interface (CLI) provides a way to suppress query results using the .mode trash command. This feature is particularly useful in scenarios where you need to execute queries but don’t want their results to be displayed.

Example

Here’s a quick example to demonstrate how it works.

Here’s what happens when we use a mode that outputs data (i.e. it doesn’t suppress output):

.mode table
SELECT 1, 2, 3;

Result:

+---+---+---+
| 1 | 2 | 3 |
+---+---+---+
| 1 | 2 | 3 |
+---+---+---+

Under normal circumstances, the result is output to the terminal like the above result.

But if we use .mode trash, it won’t be output. Let’s switch to .mode trash and run the query again:

.mode trash
SELECT 1, 2, 3;

Result:





That’s intentionally blank, because .mode trash suppressed any output from the query.

Why Suppress Query Output?

While we usually want to see the results of our queries, this isn’t necessarily always the case. For example, we might want to suppress the output during:

  • Performance Testing: When benchmarking query execution time, displaying results can add overhead and skew timing measurements
  • Batch Operations: When running multiple data modification queries, you may only care about success/failure, not the actual results
  • Data Loading: When loading large amounts of data, suppressing output keeps the terminal clean and reduces memory usage
  • Maintenance Scripts: For database maintenance tasks where you’re only interested in the final outcome

Restoring Normal Output

When you need to see query results again, switch to a mode of your choosing. For example:

.mode duckbox

That switches to duckbox, which is the default output mode in DuckDB.

Note

  • Error messages will still be displayed even in trash mode
  • The queries are still executed – only the output is suppressed
  • System dot commands (starting with ‘.‘) will still show their output

Remember to switch back to a standard output mode (like .mode duckbox or .mode table) when you need to see query results again.