# Save to MOI Table

Write structured JSON fields or batches of rows to an MOI table and return the affected row count.

Use it for extraction or query results. To import file contents in formats such as CSV or Excel, use [Save File to MOI Volume, Then Import to MOI Table](../other/volume-to-table-import.md).

## Choose a target table

Use either an existing Catalog `table_ref`, or a `database_ref` with a text `table_name`.

When selecting an existing table, omit the database and table name settings. With the name-based option, use `json_schema` to define fields and reuse or create the target table.

## Choose data to write

| Input | Description |
| --- | --- |
| `raw_json` | One JSON object; also accepts an upstream JSON object string |
| `values` | One field object; when combined with `raw_json`, overrides fields with the same name |
| `rows` | Nonempty array of objects for batch writes |
| `json_schema` | Field structure used to resolve columns |

Batch and single-object modes are mutually exclusive. Bind batches to `rows`; use `raw_json` or `values` for a single object.

## Use the output

`affected_rows` counts rows affected by inserts or updates. `written_columns` lists written fields. `database` and `table_name` identify the target; selecting a Catalog table also returns its resolved `table_ref`.

Check the destination, written columns, and affected rows after running.

## Example: save one contract extraction

Flow: Information Extraction → Save to MOI Table.

Use single-result extraction, bind `result` to `raw_json`, and configure the matching schema and target table. Inspect the extracted contract fields in the table after running.

## Related pages

- [Variables and data flow](../../variables-and-data.md)
- [Run and debug](../../run-debug.md)
