Skip to content

DuckDB Extension

Textplot

Render bars, sparklines, and density plots as text in DuckDB query results. Inspect trends directly in the CLI without exporting a chart.

36,853
extension loads Β· last 90 days
On this page
Sample data for the examples

Each browser example starts with these sample tables; sample files are shared across examples on this page. Run this setup first when trying the examples in your own DuckDB session.

-- Fixtures for textplot extension SQL examples.
-- Provides small, deterministic data so the validator can parse and
-- execute the snippets in cookbook.mdx, technical-details.mdx, and
-- metadata.json that reference real tables.

-- A numeric column with a roughly normal-looking distribution. Built
-- deterministically from generate_series + a sum of trig terms so the
-- spread is realistic (a single hump centred near zero with tails) and
-- the same numbers come out every run. Used by the `tp_density(...)`
-- "see the shape of a column" examples.
CREATE OR REPLACE TABLE measurements AS
SELECT (
         sin(i * 0.13)
       + sin(i * 0.29 + 1.7)
       + sin(i * 0.71 + 0.4)
       + sin(i * 1.13 + 2.1)
       )::DOUBLE AS value
FROM range(0, 200) t(i);

-- A handful of hosts each with a 24-point CPU history array and a
-- disk-utilization percentage. Used by the `tp_sparkline(cpu_history)`
-- and `tp_bar(disk_pct, ...)` per-row examples.
CREATE OR REPLACE TABLE hosts_status AS
SELECT
    'host-' || lpad(h::VARCHAR, 2, '0') AS host,
    [
      40 + 20 * sin(h * 0.5 + 0.0) + 5 * sin(h * 1.7 + 0.1),
      40 + 20 * sin(h * 0.5 + 0.3) + 5 * sin(h * 1.7 + 0.4),
      40 + 20 * sin(h * 0.5 + 0.6) + 5 * sin(h * 1.7 + 0.7),
      40 + 20 * sin(h * 0.5 + 0.9) + 5 * sin(h * 1.7 + 1.0),
      40 + 20 * sin(h * 0.5 + 1.2) + 5 * sin(h * 1.7 + 1.3),
      40 + 20 * sin(h * 0.5 + 1.5) + 5 * sin(h * 1.7 + 1.6),
      40 + 20 * sin(h * 0.5 + 1.8) + 5 * sin(h * 1.7 + 1.9),
      40 + 20 * sin(h * 0.5 + 2.1) + 5 * sin(h * 1.7 + 2.2),
      40 + 20 * sin(h * 0.5 + 2.4) + 5 * sin(h * 1.7 + 2.5),
      40 + 20 * sin(h * 0.5 + 2.7) + 5 * sin(h * 1.7 + 2.8),
      40 + 20 * sin(h * 0.5 + 3.0) + 5 * sin(h * 1.7 + 3.1),
      40 + 20 * sin(h * 0.5 + 3.3) + 5 * sin(h * 1.7 + 3.4),
      40 + 20 * sin(h * 0.5 + 3.6) + 5 * sin(h * 1.7 + 3.7),
      40 + 20 * sin(h * 0.5 + 3.9) + 5 * sin(h * 1.7 + 4.0),
      40 + 20 * sin(h * 0.5 + 4.2) + 5 * sin(h * 1.7 + 4.3),
      40 + 20 * sin(h * 0.5 + 4.5) + 5 * sin(h * 1.7 + 4.6),
      40 + 20 * sin(h * 0.5 + 4.8) + 5 * sin(h * 1.7 + 4.9),
      40 + 20 * sin(h * 0.5 + 5.1) + 5 * sin(h * 1.7 + 5.2),
      40 + 20 * sin(h * 0.5 + 5.4) + 5 * sin(h * 1.7 + 5.5),
      40 + 20 * sin(h * 0.5 + 5.7) + 5 * sin(h * 1.7 + 5.8),
      40 + 20 * sin(h * 0.5 + 6.0) + 5 * sin(h * 1.7 + 6.1),
      40 + 20 * sin(h * 0.5 + 6.3) + 5 * sin(h * 1.7 + 6.4),
      40 + 20 * sin(h * 0.5 + 6.6) + 5 * sin(h * 1.7 + 6.7),
      40 + 20 * sin(h * 0.5 + 6.9) + 5 * sin(h * 1.7 + 7.0)
    ]::DOUBLE[] AS cpu_history,
    -- Spread disk_pct across 10..98 so the threshold-coloured bar
    -- example exercises the green / yellow / red zones.
    (10 + (h * 13) % 89)::DOUBLE AS disk_pct
FROM range(0, 8) t(h);

See a pattern directly in query output

Textplot creates small charts from ASCII or Unicode characters and returns them as SQL strings. A result can contain a sparkline, a bar, or another compact visual alongside ordinary columns.

Use it while exploring data in the CLI or building a text report. It helps reveal a trend or distribution without opening a separate plotting tool. The output is text, so its appearance depends on the terminal’s font and support for the chosen characters.

Example

Plot a short series as a sparkline

Each value contributes to the shape of the line. The result is text that can appear alongside ordinary query columns.

Tested with DuckDB 1.5.6. Browser examples use Haybarn-Wasm 2.0.0-rc12.

SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
  WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL textplot FROM query_farm;
LOAD textplot FROM query_farm;

SELECT tp_sparkline([2, 4, 3, 7, 5, 8], width := 12) AS trend;

Expected result

trend
β–ƒβ–ƒβ–β–β–‡β–‡β–„β–„β–ˆβ–ˆ

Appearance depends on the terminal font and Unicode support. Choose ASCII output when the display cannot render block characters consistently.

Common tasks

Deep Dive

Technical Details

Reference

Extension Contents

Quick reference to all available functions and settings organized by category.

Charts
tp_bar() Object type: Scalar function Render a horizontal bar showing a numeric value as a fraction of a min/max range.
tp_density() Object type: Scalar function Render an array of numeric values as a density plot β€” a compact distribution visualization where the character intensity at each x-position reflects how many input values fall in that bin.
tp_sparkline() Object type: Scalar function Render an array of numeric values as a sparkline β€” a compact one-line trend chart.
tp_sparkline_agg() Object type: Aggregate function Aggregate form of tp_sparkline: collects a group's numeric values and renders them as one sparkline, so you can chart raw rows without building a list first.
QR Codes
tp_qr() Object type: Scalar function Encode a string or BLOB as a QR code rendered with Unicode block characters.

API Reference

Function Reference

Practical Examples

Cookbook

Real-world recipes and patterns for common use cases.

Platform Support

Compatibility

Extension availability may vary by platform and DuckDB version. Check below to ensure this extension supports your environment before installation.

Quick Facts

Release status Stable
Software License MIT
Pricing Free
Written In C++
Source Available Yes
View on GitHub
Usage
36,853
loads Β· last 90 days

Platforms

DuckDB 2.0.0

  • Linux x86_64aarch64
  • Linux (musl) Not available
  • macOS Apple Silicon
  • Windows x86_64x86_64 (MinGW)
  • WASM Not available
Compiled binary sizes
Platform Architecture Size
Linux x86_64 4.05 MB
Linux aarch64 3.41 MB
macOS Apple Silicon 2.86 MB
Windows x86_64 10.25 MB
Windows x86_64 (MinGW) 17.88 MB

Compressed download sizes for the release shown above.

DuckDB & Haybarn

Release calendar
  • DuckDB v2.0.0 Query.Farm repository Supported
  • Haybarn v1.5.6 Built-in community repository Supported

Browser examples use Haybarn-Wasm 2.0.0-rc12.

Checked .

Learn and explore

Tutorials and articles

Writing about Textplot: how it works, what changed, and why.