Search Shortcut cmd + k | ctrl + k
nats_js

Query NATS JetStream message streams directly with SQL

Maintainer(s): brannn

Installing and Loading

INSTALL nats_js FROM community;
LOAD nats_js;

Example

-- Query messages from a NATS JetStream stream
SELECT subject, seq, ts_nats, payload
FROM nats_scan('telemetry')
WHERE seq BETWEEN 1 AND 100;

-- Extract JSON fields with dot notation
SELECT device_id, zone, kw
FROM nats_scan('telemetry',
    json_extract := ['device_id', 'zone', 'kw']
);

-- Extract Protocol Buffers fields with nested navigation
SELECT device_id, location_zone, metrics_kw
FROM nats_scan('telemetry',
    proto_file := 'telemetry.proto',
    proto_message := 'Telemetry',
    proto_extract := ['device_id', 'location.zone', 'metrics.kw']
);

About nats_js

The NATS JetStream extension enables direct SQL querying of NATS JetStream message streams without establishing durable consumers.

Features:

  • Sequence-based range queries (start_seq, end_seq)
  • Timestamp-based range queries with binary search (start_time, end_time)
  • Subject filtering for targeted message retrieval
  • JSON payload extraction with dot notation for nested fields
  • Protocol Buffers support with runtime schema parsing and nested message navigation

Perfect for ETL workflows, analytics, and ad-hoc querying of message streams.

GitHub: https://github.com/brannn/duckdb-nats-jetstream

Added Functions

function_name function_type description comment examples
nats_scan table NULL NULL