duckweb_chunk

scalar · LOAD duckweb

duckweb_chunk(VARCHAR) -> VARCHAR

One chunk of a streamed body.

SELECT duckweb_chunk('<li>' || duckweb_escape(n.body) || '</li>')
FROM duckweb_match(route, '/notes'), notes n
WHERE method = 'GET'

The length prefix counts bytes, not characters, so multi-byte text frames correctly without the app having to think about it.

An empty string produces nothing at all. A zero-length chunk is the end-of-body marker, so emitting one mid-response would truncate the body — this is why a branch that renders one row per record is safe even when there are no records. duckweb_end stays the only terminator.

Rows reach the socket as DuckDB produces them, one data chunk at a time. That is what makes a slow query stream rather than buffer: the head is already at the reader while the expensive part of the plan is still running.