query_sdmx
Fetch SDMX observations and run ONE read-only SQL query over them server-side,
returning only the query result. Nothing is stored — the data is loaded into a
temporary in-memory table named data and discarded after the query.
*** Use this for compute/compare/rank questions ("which province grew fastest", "average since 2020", "year-over-year change") instead of pulling raw rows with get_sdmx_data and doing arithmetic yourself. It is not limited to 500 rows. ***
Same productId, key and time parameters as get_sdmx_data (see that tool for key syntax and wildcard rules). lastNObservations cannot be combined with startPeriod/endPeriod.
Table data columns: one per dimension (names sanitized: spaces/punctuation → '_'),
"period" (TEXT, e.g. "2024" or "2024-03"), "value" (REAL, NULL = suppressed),
plus SDMX attributes like VECTOR_ID, UOM, SCALAR_FACTOR, STATUS.
Quote mixed-case column names with double quotes.
Example — CPI growth by province since Jan 2020: productId=18100004, key="2+3+5+6.2", startPeriod="2020-01", sql: SELECT "Geography", MAX(CASE WHEN period = '2025-12' THEN value END) / MAX(CASE WHEN period = '2020-01' THEN value END) - 1 AS growth FROM data GROUP BY 1 ORDER BY growth DESC
If the SQL fails, the response includes table_columns — fix the query and retry.
Limits: one statement, SELECT only, ~2s execution time, result capped at 500 rows.
IMPORTANT: In your final response, cite the _sdmx_url, productId and key used.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| key | Yes | Dot-separated dimension codes in position order (e.g. '1.2.1'). Use '+' for OR ('1+2.2.1' = Geography 1 or 2). Omit a value for wildcard ('.2.1' = all geographies, Gender=2, Age=1). Code numbers match WDS memberIds — no translation needed. Call get_sdmx_structure first to see dimension positions and valid codes. | |
| sql | Yes | One read-only SELECT (WITH/CTEs and window functions allowed) against table 'data'. Columns: one per dimension (spaces/punctuation -> '_', e.g. "Products_and_product_groups"), period, value (REAL), VECTOR_ID, UOM, SCALAR_FACTOR, STATUS, etc. Quote mixed-case names: SELECT "Geography", ... | |
| endPeriod | No | End period in YYYY or YYYY-MM format. | |
| productId | Yes | ||
| startPeriod | No | Start period in YYYY or YYYY-MM format. | |
| lastNObservations | No | Return only the last N observations per series (e.g. 12 for one year of monthly data). |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| rows | Yes | SQL result rows (max 500). | |
| columns | Yes | Columns of the SQL result. | |
| message | No | Present when the result was truncated. | |
| _sdmx_url | Yes | SDMX request URL — cite as the data source. | |
| table_columns | Yes | Columns available in table 'data'. | |
| fetched_row_count | Yes | Rows loaded into the temporary 'data' table. |