DuckDB Extension
Radio
Receive WebSocket or Redis Pub/Sub messages in DuckDB and query the buffered events as tables. Send messages and inspect delivery state from SQL.
On this page
Collect live messages for SQL queries
Radio connects to WebSocket feeds or Redis Pub/Sub channels and buffers incoming messages inside the DuckDB process. SQL functions read those messages as rows and can queue outgoing messages.
Use it to inspect a live feed or combine recent events with local data. You need an accessible messaging endpoint. The buffers are temporary, so save messages to a table when you need to retain them beyond the running session.
Example
Read messages from a WebSocket feed
Replace the example URL with a feed you can access. Subscribe, wait briefly for messages, read the buffer, then unsubscribe.
Before you run it: Supply a working WebSocket URL. stream.example.com is a placeholder, not a demo service.
Run this example in the DuckDB CLI or a native client.
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://duckdb-extensions.query.farm';
INSTALL radio FROM query_farm;
LOAD radio FROM query_farm;
SET VARIABLE qf_feed = 'wss://stream.example.com/events';
CALL radio_subscribe(getvariable('qf_feed'));
CALL radio_listen(true, INTERVAL '2 seconds');
SELECT receive_time, channel, message
FROM radio_subscription_received_messages(getvariable('qf_feed'))
ORDER BY receive_time DESC
LIMIT 10;
CALL radio_unsubscribe(getvariable('qf_feed'));
SET allow_extension_repositories = 'allowed';
CREATE EXTENSION REPOSITORY IF NOT EXISTS query_farm
WITH PREFIX 'https://haybarn-extensions.query.farm';
INSTALL radio FROM query_farm;
LOAD radio FROM query_farm;
SET VARIABLE qf_feed = 'wss://stream.example.com/events';
CALL radio_subscribe(getvariable('qf_feed'));
CALL radio_listen(true, INTERVAL '2 seconds');
SELECT receive_time, channel, message
FROM radio_subscription_received_messages(getvariable('qf_feed'))
ORDER BY receive_time DESC
LIMIT 10;
CALL radio_unsubscribe(getvariable('qf_feed'));
INSTALL radio FROM community;
LOAD radio;
SET VARIABLE qf_feed = 'wss://stream.example.com/events';
CALL radio_subscribe(getvariable('qf_feed'));
CALL radio_listen(true, INTERVAL '2 seconds');
SELECT receive_time, channel, message
FROM radio_subscription_received_messages(getvariable('qf_feed'))
ORDER BY receive_time DESC
LIMIT 10;
CALL radio_unsubscribe(getvariable('qf_feed'));
The query can return no rows if no messages arrive. Buffers live in the DuckDB process; they are not a durable message store.
Common tasks
Deep Dive
Technical Details
What you can do with three statements
-- 1. Open a WebSocket subscription. The URL itself is the key.CALL radio_subscribe('wss://stream.example.com/events');
-- 2. (later, or in another query) drain the inboxSELECT receive_time, channel, messageFROM radio_subscription_received_messages('wss://stream.example.com/events')ORDER BY receive_time DESCLIMIT 100;
-- 3. Reply or broadcast backCALL radio_transmit_message( 'wss://stream.example.com/events', 'main', -- channel '{"type":"ack","at":"2026-04-28T12:00:00Z"}', 3, -- max_attempts INTERVAL '30 seconds' -- expire_duration);radio_subscribe opens the connection and starts buffering. radio_subscription_received_messages exposes that buffer as an ordinary table with columns (message_id, receive_time, seen_count, channel, message) (radio_received_messages adds subscription_id, subscription_url and message_type across all subscriptions) — JOIN, WHERE, GROUP BY, CREATE TABLE AS. radio_transmit_message queues an outbound message; poll radio_subscriptions for the per-subscription transmit_successes / transmit_failures counters.
Subscriptions, the received-message buffer, and the transmit queue all live in DuckDB process memory. Three things follow:
- Process exit drops everything. When DuckDB shuts down, subscriptions are torn down and unread messages are lost. For at-least-once delivery across restarts, persist drained messages to a durable store before processing.
- The received buffer is size-limited. Older messages are evicted as new ones arrive — drain with
radio_received_messagesat a cadence that keeps up with your inbound rate. On the DuckDB 2.0 build,received_messages_dropped_unseeninradio_subscriptionscounts evictions of unread messages. - Outbound delivery is asynchronous and best-effort.
radio_transmit_messagereturns once the message is queued; the per-subscriptiontransmit_successes,transmit_failures,transmit_last_success_time, andtransmit_last_failure_timecolumns onradio_subscriptionsreport progress.
Status is experimental. The function surface may change as more transports get added.
Architecture
Radio runs an asynchronous I/O thread per subscription. For WebSocket endpoints it speaks the standard frame protocol; for Redis Pub/Sub endpoints it opens a Redis connection and SUBSCRIBEs to the channel(s). Inbound messages land in a per-subscription FIFO buffer; outbound messages live in a transmit queue with a status field that the I/O thread updates as delivery completes.
DuckDB SQL never blocks on the wire — radio_received_messages and friends are pure table scans over the in-process buffer. If you want to wait for fresh messages before reading, radio_listen blocks the connection until something arrives or a timeout elapses, and radio_sleep is a convenience for polling loops.
Supported transports today
- WebSocket —
ws://for plaintext,wss://for TLS. Subscribe with the URL inradio_subscribe. Standard RFC 6455 framing; the extension handles ping/pong and reconnect internally. - Loopback (DuckDB 2.0 build) —
loopback://nameopens no connection; messages transmitted on it are delivered to its own receive queue. Use it for tests and offline experiments; it works even whenenable_external_accessis false. - Redis Pub/Sub — point a subscription at a Redis URL plus channel name. Same
radio_subscribe/radio_received_messages/radio_transmit_messagesurface; Radio handles the Redis-specificSUBSCRIBEandPUBLISHunder the hood.
The extension’s documentation page lists planned transports — Google Pub/Sub, Azure Service Bus, MQTT, subprocess pipes — but only WebSocket and Redis Pub/Sub are wired up today.
DuckDB 2.0 build changes
- Sandboxing.
radio_subscribeandradio_transmit_messagerefuse WebSocket and Redis URLs whenenable_external_accessis false. - No lost wake-ups.
radio_listenno longer misses a message that arrives just as it starts waiting (which made it sleep for the full timeout and return nothing), concurrent listeners no longer cancel each other’s wake-ups, andradio_listen,radio_flushandradio_sleepcan be interrupted. - Prepared statements. Every
radio_*table function reads current state when the query runs, so a prepared statement returns rows on everyEXECUTE(previouslyradio_subscribe,radio_transmit_messageand friends returned nothing after the first execution, and the listing functions showed a snapshot from when the statement was prepared). - New columns.
radio_subscriptions()addsreceived_messages_queuedandreceived_messages_dropped_unseen. - Inputs.
radio_subscription_received_message_addacceptsVARCHARmessages and aNULLchannel; NULL arguments elsewhere raise clear errors; a negativeradio_sleepduration is an error. - Version.
radio_version()returns the build version (YYYYMMDDNN).
Compared to alternatives
- A standalone consumer service — the typical pattern (Node.js / Python listening to WebSocket → write to a database → DuckDB queries the database). Radio collapses that into one process and keeps the data in DuckDB’s vectorized executor without a serialization hop. The trade is durability: a real consumer service can crash-restart from the bus.
- The
shellfsextension pipingwscat/websocatoutput — works for read-only WebSocket streams, but each pipe is a one-shot command without bidirectional support, status tracking, or reconnect. - Kafka via
tributary— different kind of bus. Tributary is for snapshotting / scanning Kafka topics; Radio is for live channel subscribe-and-send semantics on WebSocket / Redis Pub/Sub.
Reference
Extension Contents
Quick reference to all available functions and settings organized by category.
| Name | Type | Description |
|---|---|---|
|
Inbox
Queryable table views of received messages — across all subscriptions or filtered to one. Drain like any DuckDB table; the buffer is in-process and FIFO per subscription. |
||
| radio_received_messages() | Object type: Table function |
Returns the messages held in every subscription's receive queue: subscription_id, subscription_url, message_id, message_type (message, error, connection, disconnection), receive_time, seen_count, channel and the message payload as BLOB (use decode(message) for UTF-8 text).
|
| radio_subscription_received_message_add() | Object type: Table function |
Adds a message to a subscription's receive queue as if it had arrived from the network and returns its message_id.
|
| radio_subscription_received_messages() | Object type: Table function |
Returns the messages in one subscription's receive queue: message_id, receive_time, seen_count, channel and message (BLOB).
|
|
Listening
Open and manage subscriptions to remote event sources (WebSockets, message buses). Each subscription has a name and an endpoint; incoming messages are buffered for SQL to drain. |
||
| radio_listen() | Object type: Table function |
Returns the subscriptions (subscription_id, subscription_url) holding received messages that no query has read yet.
|
| radio_subscribe() | Object type: Table function |
Opens a subscription and returns its subscription_id.
|
| radio_subscriptions() | Object type: Table function |
Lists the active subscriptions: subscription_id, url, creation_time, activation_time (NULL until connected), disabled, received_last_message_time, received_messages_processed, transmit_messages_processed, transmit_last_queue_time, transmit_last_success_time, transmit_last_failure_time, transmit_successes and transmit_failures.
|
| radio_unsubscribe() | Object type: Table function |
Closes the subscription for a URL and returns its subscription_id.
|
|
Maintenance
Buffer flushing, polling sleeps, and version inspection. |
||
| radio_flush() | Object type: Table function |
Waits up to timeout for every subscription's transmit queue to finish (send, or give up on) its pending messages.
|
| radio_sleep() | Object type: Table function |
Sleeps for duration and returns true.
|
| radio_version() | Object type: Scalar function | Returns the version of the loaded Radio extension. |
|
Outbox
Send messages out, with built-in delivery tracking. Queue, inspect, retract, and garbage-collect — all from SQL. |
||
| radio_subscription_transmit_message_delete() | Object type: Table function |
Removes one message, by message_id, from a subscription's transmit queue, cancelling it if it has not been sent yet.
|
| radio_subscription_transmit_messages() | Object type: Table function |
Returns one subscription's transmit queue: message_id, creation_time, last_attempt_start_time, last_attempt_end_time, state (pending, sending, sent, retries_exhausted, time_expired), expire_duration_ms, max_attempts, try_count, channel, message and result (the last transport error, if any).
|
| radio_subscription_transmit_messages_delete_finished() | Object type: Table function |
Removes the transmit messages of a subscription that are finished — sent, retries_exhausted or time_expired — and returns true.
|
| radio_transmit_message() | Object type: Table function |
Queues message for sending on the subscription for url and returns its message_id.
|
No extension contents match that search.
API Reference
Function Reference
Practical Examples
Cookbook
Real-world recipes and patterns for common use cases.
Subscribe to a WebSocket channel
-- Open a subscription. The URL itself is the subscription identifier —-- pass it to the read / send / unsubscribe functions later.CALL radio_subscribe('wss://stream.example.com/events');
-- Inspect what's subscribedSELECT * FROM radio_subscriptions();The URL is what every other radio_* function takes as its subscription key. If you’ll reuse it across many statements, stash it in a SQL variable and bind via :feed:
SET VARIABLE feed = 'wss://stream.example.com/events';
CALL radio_subscribe(getvariable('feed'));
SELECT * FROM radio_subscription_received_messages(getvariable('feed'));See radio_subscribe and radio_subscriptions for the full signatures, including the optional named parameters for buffer sizing and transmit retry tuning.
Subscribe to Redis Pub/Sub
Same function, different URL — Radio routes WebSocket and Redis Pub/Sub through the same surface:
CALL radio_subscribe('redis://cache.example.com:6379/0?channel=events');
-- Drain the same way as a WebSocket subscription, keyed by URLSELECT receive_time, messageFROM radio_subscription_received_messages('redis://cache.example.com:6379/0?channel=events')ORDER BY receive_time DESC;Drain received messages
-- Recent messages across all subscriptionsSELECT subscription_url, channel, receive_time, messageFROM radio_received_messages()ORDER BY receive_time DESCLIMIT 100;-- One feed only — pass the same URL you subscribed withSELECT receive_time, channel, messageFROM radio_subscription_received_messages('wss://stream.example.com/events')ORDER BY receive_time DESC;The full row shape from radio_received_messages() / radio_subscription_received_messages(url) is (subscription_id UBIGINT, subscription_url VARCHAR, message_id UBIGINT, message_type, receive_time TIMESTAMP_MS, seen_count UBIGINT, channel VARCHAR, message BLOB). The payload is a BLOB — turn UTF-8 text into a VARCHAR with decode(message), then use DuckDB’s JSON functions for structured payloads. (A plain message::VARCHAR cast escapes quotes and non-ASCII bytes in DuckDB 2.0.) These are normal DuckDB table functions — JOIN, filter, aggregate, push to Parquet, anything you’d do with a regular table. See radio_received_messages and radio_subscription_received_messages.
Wait for fresh messages before reading
For loops that need to act as messages arrive (rather than polling on a timer), radio_listen blocks the connection until something lands in the inbox or a timeout elapses:
-- Block up to 30 seconds for an unread message on any subscription.-- Args: (wait_for_messages, timeout). Returns the subscriptions with unread messages.CALL radio_listen(true, INTERVAL '30 seconds');
-- Then drainSELECT * FROM radio_received_messages() ORDER BY receive_time DESC LIMIT 1;Reading messages marks them seen, so the next radio_listen waits for new ones. Pair with radio_sleep when scripting between polls. On the DuckDB 2.0 build a message that arrives while radio_listen is starting its wait is never missed, and the wait can be interrupted with Ctrl-C.
Send a message and track delivery
-- Args: (subscription_url, channel, payload, max_attempts, expire_duration).-- A message not delivered within expire_duration moves to the time_expired state.CALL radio_transmit_message( 'wss://stream.example.com/events', /* channel */ 'main', /* payload */ '{"type":"hello","at":"2026-04-28T12:00:00Z"}', /* max_attempts */ 3, /* expire_duration */ INTERVAL '30 seconds');
-- Inspect transmit queue + delivery stateSELECT message_id, messageFROM radio_subscription_transmit_messages('wss://stream.example.com/events')ORDER BY message_id DESC;A VARCHAR payload goes out as a WebSocket text frame, which JSON APIs such as Slack expect; pass a BLOB ('...'::BLOB) to send a binary frame instead. The bytes are sent as-is either way. A NULL payload is an error.
Per-subscription delivery counters live on radio_subscriptions (transmit_successes, transmit_failures, transmit_last_success_time, transmit_last_failure_time); poll those to confirm delivery progress. See radio_transmit_message and radio_subscription_transmit_messages.
Garbage-collect the outbox
-- Drop all already-delivered transmit messagesCALL radio_subscription_transmit_messages_delete_finished('wss://stream.example.com/events');-- Or drop one specific pending outgoing message. Replace 42 with a message_id-- from radio_subscription_transmit_messages.CALL radio_subscription_transmit_message_delete('wss://stream.example.com/events', 42::UBIGINT);See radio_subscription_transmit_messages_delete_finished and radio_subscription_transmit_message_delete.
Test pipelines without a real upstream
Inject messages straight into a subscription’s inbox to exercise downstream SQL — no broker, no real WebSocket, no flake. On the DuckDB 2.0 build the loopback:// transport needs no server at all: messages transmitted on it come back to the same subscription.
CALL radio_subscribe('loopback://test');-- Inject a message as if it had arrived from the networkCALL radio_subscription_received_message_add('loopback://test', 'orders', '{"type":"test","value":42}');
-- Or transmit one and let the loopback deliver itCALL radio_transmit_message('loopback://test', 'orders', '{"type":"test","value":43}', 3, INTERVAL '10 seconds');CALL radio_flush(INTERVAL '5 seconds');
SELECT channel, decode(message)::JSON ->> 'value' AS valueFROM radio_subscription_received_messages('loopback://test')ORDER BY message_id;See radio_subscription_received_message_add. On the Haybarn 1.5 build, which has no loopback transport, inject into any subscribed URL instead (the message must be a BLOB there).
Detect dropped messages
Each subscription’s receive queue holds receive_message_capacity messages (default 1000) and evicts the oldest when full. On the DuckDB 2.0 build, radio_subscriptions counts the evicted messages nobody had read:
SELECT url, received_messages_queued, received_messages_dropped_unseenFROM radio_subscriptions();If received_messages_dropped_unseen grows, read more often or resubscribe with a larger receive_message_capacity.
Tear down
-- Close the subscriptionCALL radio_unsubscribe('wss://stream.example.com/events');See radio_unsubscribe.
Diagnostics
SELECT radio_version(); -- e.g. '2026110701' on the DuckDB 2.0 buildUse radio_version to confirm what’s loaded when matching against bug reports. radio_flush waits for every subscription’s outgoing messages to be sent (or given up on) and returns whether they all finished in time — it does not touch received messages.
Sandboxed sessions
On the DuckDB 2.0 build, radio_subscribe and radio_transmit_message refuse WebSocket and Redis URLs once enable_external_access is false:
SET enable_external_access = false;CALL radio_subscribe('wss://stream.example.com/events');-- Permission Error: radio_subscribe is disabled because enable_external_access is falseExisting subscriptions can still be inspected, and loopback:// subscriptions keep working.
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 Not available
- WASM Not available
Compiled binary sizes
| Platform | Architecture | Size |
|---|---|---|
| Linux | x86_64 | 7.03 MB |
| Linux | aarch64 | 6.62 MB |
| macOS | Apple Silicon | 5.21 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 Radio: how it works, what changed, and why.
-
Radio for DuckDB 2.0: listen again, and see what the queue lost
Radio fixes missed wakeups and repeated prepared statements, exposes dropped messages, and preserves text and binary WebSocket payloads in DuckDB.