write_table¶
Write model-supplied rows to a file in any writable format. It is the
inverse of read_table: you provide the schema and the
rows inline, and Octa serialises them through its FormatRegistry based
on the output extension.
When to use¶
- "Save these rows as a CSV / Parquet / Excel file."
- "Create a small lookup table from this data."
- "Append these new records to the existing export."
For editing an existing file's cells or rows, use
edit_table. For persisting a SQL result to a database,
use run_sql with write_to.
Input schema¶
| Parameter | Type | Required? | Default | Description |
|---|---|---|---|---|
path |
string | yes | (no default) | Destination file path. Format inferred from extension |
columns |
array | yes | (no default) | Column definitions, in order. Each is { "name": string, "type"?: string } |
rows |
array | no | [] |
Array-of-arrays. Each inner array is one row, lined up positionally with columns |
mode |
string | no | create |
create (error if file exists), overwrite (replace), or append (add to existing) |
unlimited |
bool | no | false |
Lift the 5,000,000-row file-loader cap when reading the existing file for append |
type is an Arrow type name (e.g. Int64, Float64, Boolean,
Date32, Timestamp(Microsecond, None), Utf8) and defaults to Utf8.
Cells are coerced to the column type: integers into a Float64 column
become floats; a string into a Binary column is hex-decoded when it is
valid hex; JSON arrays/objects are stored verbatim as nested text.
The rows shape is identical to what read_table returns, so a read
result round-trips straight back in.
Response shape¶
Example calls¶
Create a CSV from inline rows¶
{
"name": "write_table",
"arguments": {
"path": "/tmp/people.csv",
"columns": [
{ "name": "id", "type": "Int64" },
{ "name": "name", "type": "Utf8" }
],
"rows": [[1, "alice"], [2, "bob"]],
"mode": "create"
}
}
Response:
Append rows to an existing file¶
{
"name": "write_table",
"arguments": {
"path": "/tmp/people.csv",
"columns": [
{ "name": "id", "type": "Int64" },
{ "name": "name", "type": "Utf8" }
],
"rows": [[3, "carol"]],
"mode": "append"
}
}
In append mode the file must already exist and its column names must
match columns; otherwise the call errors with an
append column mismatch message.
Modes and safety¶
createrefuses to clobber an existing file (returns an error telling you to useoverwriteorappend).overwritereplaces the whole file without prompting.appendreads the existing file fully (passunlimited: truefor very large files), validates the schema, and rewrites it with the extra rows. For row-oriented formats this is a full rewrite, not an in-place append.
Read-only and database targets¶
- Read-only output formats (SAS, RDS, HDF5, NetCDF, EPUB, GeoJSON) are
rejected up front, the same as
convert. - Database files (
.sqlite,.duckdb) are not validwrite_tabletargets, because their writers need a table loaded from the database (diff-based save). Useedit_tableto edit an existing database table, orrun_sqlwrite_toto persist a query result.
See also¶
read_tableis the inverse read.edit_tableedits an existing file in place.- Supported formats is the full read/write matrix.