Search Shortcut cmd + k | ctrl + k

Read and write NATS JetStream streams with SQL

Maintainer(s): robert-guangzhou, xiehuiqiang

Compatibility Matrix

This table covers all DuckDB releases that have not reached end-of-life, including LTS releases, and shows the 2 most recent patch releases of each. Older patch releases are not listed, but the extension may be available for them as well.

Platform 1.4.4 1.4.5 1.5.5 1.5.6 2.0.0
Linux AMD64
Linux ARM64
macOS AMD64
macOS ARM64
Windows AMD64
Windows ARM64
WebAssembly

Installing and Loading

INSTALL nats_rw FROM community;
LOAD nats_rw;

Example

-- Write query results to a NATS JetStream stream
COPY (SELECT 'hello' AS v) TO 'my_stream'
  (FORMAT nats_rw, url 'nats://localhost:4222', create_stream 'true');

-- Read it back
SELECT * FROM nats_rw_scan('my_stream', url := 'nats://localhost:4222');

-- Extract JSON fields as columns
SELECT device_id, location_zone
FROM nats_rw_scan('my_stream', url := 'nats://localhost:4222',
    json_extract := ['device_id', 'location.zone']);

About nats_rw

The nats_rw extension provides bidirectional NATS JetStream access from DuckDB:

  • Read: nats_rw_scan() table function — bounded snapshot scan with subject filtering, sequence/time ranges, JSON field extraction, and predicate pushdown (WHERE seq/ts_nats automatically narrows the scan range)
  • Write: COPY … TO '<stream>' (FORMAT nats_rw) — publish query results with optional payload_column, subject_prefix, and auto stream creation
  • Auth: CREATE SECRET (TYPE nats_rw, …) — user/password, token, nkey, or credentials file, with scope-based auto-matching
  • Metadata: nats_rw_streams() and nats_rw_stream_info() for inspection
  • Performance: connection pooling (per-url cache) + predicate pushdown

Connections are cached per (url, auth) for efficient repeated queries.

Documentation: https://github.com/robert-guangzhou/duckdb-nats-rw

Added Functions

function_name function_type description comment examples
nats_rw_scan table NULL NULL  
nats_rw_stream_info table NULL NULL  
nats_rw_streams table NULL NULL  
nats_rw_version scalar NULL NULL  

Overloaded Functions

This extension does not add any function overloads.

Added Types

This extension does not add any types.

Added Settings

name description input_type scope aliases typed_value
temp_directory Set the directory to which temporary files are written. VARCHAR GLOBAL [] post.db.tmp
© 2026 DuckDB Foundation, Amsterdam NL
DuckDB Home Code of Conduct Trademark Use Blog