Openfda Dataframe Query
openfda_dataframe_queryRun a read-only SQL SELECT against a DataCanvas table staged by an openFDA search tool (call one with stage=true; its response carries canvas_id + canvas_table). Enables GROUP BY, COUNT/SUM/AVG, time-series, and joins across the staged result set without re-paging the API. Call openfda_dataframe_describe first to get the exact table and column names. Results are capped at the canvas row limit — when truncated is true, page the rest with ORDER BY plus LIMIT/OFFSET. Scalar fields are stored as text (CAST for numeric math); nested objects/arrays are JSON columns — read them with DuckDB json functions, e.g. json_extract_string(openfda, '$.brand_name[0]'). Only SELECT is allowed — DDL, DML, COPY, and file-reading functions are blocked.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | SQL SELECT against the staged table. Use the table name from openfda_dataframe_describe. Example: "SELECT classification, COUNT(*) AS n FROM spilled_ab12cd34 GROUP BY classification ORDER BY n DESC". | |
| canvas_id | Yes | Canvas ID from an openFDA search tool response (the canvas_id field, present when the search ran with stage=true). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | No | Rows returned by the query (capped at the canvas row limit). | |
| error | No | Present when the call failed. Absent on success. | |
| canvas_id | No | Canvas ID that was queried — reuse for follow-up queries. | |
| row_count | No | Number of rows in this response. Equals the canvas row limit when truncated is true. | |
| truncated | No | True when the result hit the canvas row limit and rows beyond it were dropped. Page the rest with ORDER BY plus LIMIT/OFFSET. |