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.
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;
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://haybarn-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;
INSTALL textplot FROM community;
LOAD textplot;
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
What you can do with one query
The shortest path from βa column of numbersβ to βI can see whatβs going onβ β without leaving the DuckDB CLI:
SELECT tp_density(array_agg(value)) AS distributionFROM measurements;tp_density renders the array as a one-line Unicode density plot β enough to tell whether the data is roughly normal, bimodal, or has a long tail. No notebook, no matplotlib, no BI tool round-trip. The same shape works for sparklines and threshold-colored bars in any result table:
SELECT host, tp_sparkline(cpu_history, theme := 'utf8_blocks', width := 24) AS cpu, tp_bar(disk_pct, min := 0, max := 100, width := 12, thresholds := [(90, 'red'), (75, 'yellow'), (0, 'green')]) AS diskFROM hosts_statusORDER BY disk_pct DESC;One sparkline per row, one threshold-colored bar per row, all inline in the result table.
Textplot is a CLI ergonomics tool. Character-grid resolution caps the detail you can see β these plots are for quick visual checks during interactive SQL, not a replacement for Matplotlib, Vega-Lite, or a proper BI dashboard. When you need axes, hover, drilldown, or pixels, use a real charting tool. When you just want to know the shape of a column without leaving the terminal, use this.
How it fits the CLI workflow
Every function returns a single VARCHAR. Thatβs the whole API: any chart you produce is just another column in the result set. It composes with .mode line, .mode markdown, log redirection, tee to a file, or paste into a status email β same as any other string column.
The companion piece for the CLI is fuzzycomplete, which fixes tab-completion for table and column names. Together theyβre the two extensions worth installing for βI live in the DuckDB REPLβ workflows: fuzzycomplete makes typing queries painless, textplot makes reading their output painless.
Function map
| Function | Shape | Use for |
|---|---|---|
tp_bar |
Single bar | Progress, percentages, SLA indicators |
tp_sparkline |
One-line trend | Time series, KPIs in tables |
tp_sparkline_agg |
One-line trend (aggregate) | Charting a series straight from rows, per group (DuckDB 2.0 build) |
tp_density |
Distribution plot | Spotting outliers, shape of a column |
tp_qr |
QR code | Scannable links in terminal/docs |
Styling vocabulary
The named-parameter surface is shared in spirit across functions:
- Shapes / styles / themes β
shape := 'circle' | 'square' | 'heart'ontp_bar; named character-set styles ontp_density(shaded,ascii,dots,height,circles,rainbow_circle, β¦); per-mode themes ontp_sparkline(utf8_blocks,arrows,faces,slopes, β¦). - Colors β
on_color/off_colorontp_bar.thresholds := [(threshold, color), ...]gives value-conditional coloring; each block uses the highest threshold it satisfies. - Custom characters β
tp_barandtp_qrtakeon/off, andtp_densitytakesgraph_charsandmarker; all accept arbitrary strings (single chars, emoji, multi-char sequences).onandoffare SQL reserved words β quote them as"on"and"off". - Width β fixed character width keeps charts aligned in tables.
Named parameters
Each function takes one positional argument β the value, list, or data to plot β and every option is a keyword-only named parameter with a default, declared natively in the function signature:
SELECT tp_bar(75, min := 0, max := 100, width := 20);- Pass options by name, in any order. A positional option such as
tp_bar(0.5, 0, 1)is rejected; so is an option name the function doesnβt declare. - Values are cast to the declared type β
width := 4::UTINYINTis fine β but there is no lossy implicit cast:width := 2.5is an error, and a string that doesnβt parse (marker_value := 'x') fails the cast. - Options must be constant within a query (a literal, a constant expression, or a prepared-statement
?parameter), not a per-row column. - An explicit
NULLoption makes the resultNULL, the same as aNULLfirst argument. - Some defaults mean βnot passedβ:
style := ''ontp_densitymeansshaded(unlessgraph_charsis given),theme := ''ontp_sparklinepicks the modeβs default theme,on/off:=''use the built-in glyphs,marker_value := NaNmeans no marker, andgraph_chars := []means βusestyleβ.
An unknown option, a positional option, or a value of the wrong type fails at bind time with DuckDBβs standard No function matches the given name and argument types error, which lists the full signature with every option and its default:
Binder Error: No function matches the given name and argument types 'tp_bar(DECIMAL(2,1), "bogus" := INTEGER_LITERAL)'. Candidate functions: tp_bar("value" DOUBLE, /, *, min DOUBLE := 0.0, max DOUBLE := 1.0, width BIGINT := 10, "on" VARCHAR := , "off" VARCHAR := , on_color VARCHAR := red, off_color VARCHAR := white, shape VARCHAR := square, filled BOOLEAN := true, thresholds ANY := []) -> VARCHARValue checks β ranges, allowed shapes/styles/themes/ECC levels, min < max, marker requiring marker_value, style vs graph_chars β still run at bind time with textplotβs own messages (for example tp_bar: 'width' argument must be at least 1). duckdb_functions() reports every option with its real name and type.
Portability: ASCII vs Unicode
Defaults use Unicode block characters and emoji, which look great in modern terminals but vary by font. For maximum portability:
-- ASCII-only density plotSELECT tp_density([1, 5, 3, 8, 2], style := 'ascii');-- ASCII sparklineSELECT tp_sparkline([1, 3, 2, 5, 4, 6], theme := 'ascii_basic');-- ASCII bar with custom charactersSELECT tp_bar(0.7, "on" := '#', "off" := '-', width := 15);-- ASCII QR codeSELECT tp_qr('https://query.farm', "on" := '##', "off" := ' ');For QR codes specifically, .mode ascii in the CLI gives the cleanest rendering β the default table borders interact poorly with multi-line block output.
Changes in the DuckDB 2.0 build
The November 2026 DuckDB 2.0 build of Textplot adds:
tp_sparkline_aggβ an aggregate form oftp_sparklinethat takes the samewidth,modeandthemeoptions:tp_sparkline_agg(v, width := 30 ORDER BY t). Options go beforeORDER BY. It returns exactlytp_sparkline(list(v ORDER BY t)), skips NULL/NaN/infinite values, returns NULL for a group with no non-NULL value, and works as a window function.- Extreme values plot correctly. When the spread of the values overflows a double (for example
-1.7e308and1.7e308in the same list),tp_sparkline,tp_densityandtp_barused to collapse every point into one bin; they now scale such ranges correctly. - A clear error for oversized QR payloads. Data that does not fit in a QR code now fails with
tp_qr: data of N bytes is too long for a QR code at ecc level 'β¦'instead of a generic error. The largest QR code holds 2,953 bytes atecc := 'low', and less at higher levels. - Function categories. Every function reports categories in
duckdb_functions()(visualization, plusqrfortp_qrandaggregatefortp_sparkline_agg).
When to reach for it (and when not to)
Reach for Textplot when:
- Youβre in the DuckDB CLI doing ad-hoc analysis and want to see a distribution or trend without copying values out.
- You need per-row visual cells in a result table β sparklines per host, bars per SLA, etc.
- The output goes to a terminal, log file, status email, or README.
Reach for a real charting tool when:
- Youβre building an interactive web dashboard with hover/zoom/drilldown.
- You need precise pixel control for publication-quality figures.
- The audience expects polished graphics and the data deserves them.
The two are complementary, not competing β Textplot is the βIβm at a SQL prompt right nowβ tool.
Reference
Extension Contents
Quick reference to all available functions and settings organized by category.
| Name | Type | Description |
|---|---|---|
|
Charts
Render numeric values and arrays as Unicode/ASCII charts directly in your query results β bars, sparklines, and density plots that fit in a single VARCHAR cell. |
||
| 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
Encode strings as QR codes rendered as Unicode-block art. Useful for dashboards, terminal output, and embedding scannable links in docs. |
||
| tp_qr() | Object type: Scalar function | Encode a string or BLOB as a QR code rendered with Unicode block characters. |
No extension contents match that search.
API Reference
Function Reference
Practical Examples
Cookbook
Real-world recipes and patterns for common use cases.
These examples use DuckDB 2.0 or later. Complete the repository setup and installation first.
Recipes for inline ASCII / Unicode plots in the DuckDB CLI β distributions, trends, bars, and QR codes that live as VARCHAR columns in your SELECT output.
See the shape of a column
The headline use β point an aggregate at tp_density and youβve got a one-line distribution plot in CLI output:
SELECT tp_density(array_agg(value)) AS distributionFROM measurements;For a wider plot or a different character set:
SELECT tp_density(array_agg(value), width := 40, style := 'height') AS distributionFROM measurements;Available styles: shaded (default), ascii, dots, height, circles, safety, rainbow_circle, rainbow_square, moon, sparse, white. See tp_density for the full parameter list.
Sparkline per row in a status table
The pattern that makes tp_sparkline most useful β pre-aggregate a series per entity, render a sparkline cell:
SELECT host, tp_sparkline(cpu_history, theme := 'utf8_blocks', width := 24) AS cpu_24hFROM hosts_statusORDER BY host;Three modes change what the sparkline encodes:
-- Absolute mode (default) β height β valueSELECT tp_sparkline([45.2, 47.1, 46.8, 49.3, 52.1, 48.7]);-- Delta mode β direction of change between consecutive pointsSELECT tp_sparkline([100, 105, 102, 108, 95], mode := 'delta');-- Trend mode β direction with magnitudeSELECT tp_sparkline([100, 110, 105, 125, 90], mode := 'trend', theme := 'intensity');Sparklines straight from rows
When the series lives in rows rather than an array column, aggregate it per entity. tp_sparkline_agg is the aggregate form of tp_sparkline β put ORDER BY inside the call, after any options, so the points are plotted in time order:
-- browser-unavailable: tp_sparkline_agg is new in the DuckDB 2.0 build. Run this example in native DuckDB 2.0.SELECT host, tp_sparkline_agg(cpu, width := 12 ORDER BY ts) AS cpu_trendFROM (SELECT 'host-' || (i % 3) AS host, i // 3 AS ts, 40 + 20 * sin(i * 0.37) AS cpu FROM range(36) t(i))GROUP BY host ORDER BY host;On any build, tp_sparkline(list(v ORDER BY t)) gives the same result β list(... ORDER BY ...) fixes the order the array is built in:
SELECT host, tp_sparkline(list(cpu ORDER BY ts), width := 12) AS cpu_trendFROM (SELECT 'host-' || (i % 3) AS host, i // 3 AS ts, 40 + 20 * sin(i * 0.37) AS cpu FROM range(36) t(i))GROUP BY host ORDER BY host;Without an ORDER BY, the order in which DuckDB feeds rows to an aggregate is not guaranteed, so the sparkline can change from run to run.
Threshold-colored health bars
tp_bar with a thresholds list is the natural shape for SLA, disk-utilization, or risk indicators. Each block adopts the highest threshold β€ value:
SELECT host, disk_pct, tp_bar(disk_pct, min := 0, max := 100, width := 14, thresholds := [ {'threshold': 90, 'color': 'red'}, {'threshold': 75, 'color': 'yellow'}, {'threshold': 0, 'color': 'green'} ]) AS diskFROM hosts_statusORDER BY disk_pct DESC;Sort by the underlying number; let the bar carry the visual.
ASCII output for portable terminals
When the destination doesnβt render emoji or wide Unicode reliably (older terminals, log aggregators, plain-text email), pin every function to its ASCII vocabulary:
-- DensitySELECT tp_density([1, 5, 3, 8, 2], style := 'ascii');-- SparklineSELECT tp_sparkline([1, 3, 2, 5, 4, 6], theme := 'ascii_basic');-- Bar with custom characters ("on" / "off" are reserved β quote them)SELECT tp_bar(0.7, "on" := '#', "off" := '-', width := 15);-- QR code in ASCII blocksSELECT tp_qr('https://query.farm', "on" := '##', "off" := ' ');Per-row charts on a generated series
Useful when youβre prototyping or want to demo the styling vocabulary without a real dataset:
SELECT round(n, 4) AS value, tp_bar(n, width := 14, shape := 'circle', off_color := 'black', filled := true, thresholds := [ (0.8, 'red'), (0.7, 'orange'), (0.6, 'yellow'), (0.0, 'green') ]) AS barFROM (SELECT random() AS n FROM generate_series(1, 10));QR codes for terminal output
-- Default monochromeSELECT tp_qr('Hello, World!');-- High error correction (more redundancy, slightly larger code)SELECT tp_qr('https://query.farm', ecc := 'high');-- Custom emoji stylingSELECT tp_qr('https://query.farm', ecc := 'high', "on" := 'π‘', "off" := 'β«');In the DuckDB CLI, .mode ascii gives the cleanest rendering of QR output β the default table borders interact poorly with the multi-line block grid.
Pair with fuzzycomplete for a CLI-first workflow
Textplot makes CLI output readable; fuzzycomplete makes CLI input tolerable (VS-Code-style fuzzy tab-completion across schemas and databases). Install both if you live in the DuckDB REPL:
-- browser-unavailable: Fuzzycomplete integrates with the native DuckDB CLI. Run this setup in that CLI.INSTALL fuzzycomplete FROM query_farm;LOAD fuzzycomplete FROM query_farm;
INSTALL textplot FROM query_farm;LOAD textplot FROM query_farm;Tips
- Pick widths to match your output β width 20β30 for dashboards, 10β15 for compact reports, β₯40 for distribution shapes you want to actually read.
- Combine with raw numbers, donβt replace them β the visual is for shape; the number is for precision. Show both.
- Sparklines shine in tables β one cell per row is where they earn their keep.
- ASCII for portability, emoji for impact β emoji needs a Unicode-capable terminal and font.
- For real visualization, use a real tool β Textplot is for eyeballing in the CLI, not for the dashboard you ship to stakeholders.
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
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.
-
Textplot for DuckDB 2.0: a sparkline for each group
Textplot adds tp_sparkline_agg for grouped and windowed SQL charts in DuckDB 2.0, native named options, and reliable scaling across extreme numeric ranges.