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.5.5 1.5.6 2.0.0 2.0.1
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 access from DuckDB:

  • Read: nats_rw_scan() table function — bounded snapshot scan with subject filtering, sequence/time ranges, JSON field extraction, and predicate pushdown
  • Write: COPY … TO '<stream>' (FORMAT nats_rw) — JetStream publish with optional payload_column, subject_prefix, and auto stream creation
  • Publish: nats_rw_publish() / nats_rw_publish_batch() — core NATS fire-and-forget (v0.2.0), with optional PING/PONG confirm
  • Stats: nats_rw_publish_stats() — per-URL published/errors counters with atomic reset (v0.2.0)
  • Auth: CREATE SECRET (TYPE nats_rw, …) — user/password, token, nkey, or credentials file, with scope-based auto-matching
  • TLS: four optional secret fields — TLS_ROOT_CERT, TLS_REQUIRED, TLS_CLIENT_CERT + TLS_CLIENT_KEY (mTLS)
  • Metadata: nats_rw_streams() and nats_rw_stream_info() for inspection
  • Performance: connection pooling + predicate pushdown

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

Added Functions

function_name function_type description comment examples
nats_rw_publish scalar NULL NULL  
nats_rw_publish_batch table NULL NULL  
nats_rw_publish_stats table NULL NULL  
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