Execute SQL SELECT queries directly against the datastore. Supports standard SQL syntax for querying datasets with JOINs, aggregations, WHERE clauses, and column selection. Limited to SELECT statements on public datasets only. This endpoint provides maximum flexibility for data retrieval when the simple query endpoint doesn't meet your needs. Useful for complex filtering, joining multiple tables, or computing aggregations on the server side.
From spec: Execute a SQL query against the datastore. Limited to SELECT statements on public datasets.
Usage Tips
- Only SELECT statements are allowed; no INSERT, UPDATE, DELETE
- Query must be URL-encoded when passed as a query parameter
- Use square bracket notation for dataset names: [dataset_id][index]
- Returns 400 for syntax errors with detailed error messages
Parameters (1)
query(string, query, required)
SQL SELECT query
Examples (1)
SQL Query - Select dialysis facility data with limitprobe-gate
import requests
resp = requests.get(
"https://data.cms.gov/provider-data/api/1/datastore/sql",
params={
'query': '[SELECT * FROM a106bb7d-22a0-5be5-be84-af58b992c236][LIMIT 5]',
},
)
data = resp.json()
import zingu_apis
api = zingu_apis.api("cms-provider-data")
result = api.fetch("datastore/sql", query="[SELECT * FROM a106bb7d-22a0-5be5-be84-af58b992c236][LIMIT 5]")
for item in result:
print(item)
const resp = await fetch("https://data.cms.gov/provider-data/api/1/datastore/sql?query=%5BSELECT+%2A+FROM+a106bb7d-22a0-5be5-be84-af58b992c236%5D%5BLIMIT+5%5D");
const data = await resp.json();