- Data
- MCP server
- Direct query
- Read-only SQL on the warehouse
Read-only SQL on the warehouse
query_sqlRun a read-only SQL statement against the property warehouse. SELECT and
Same call over REST
Query SQL/v1/query/sqlNot connected yet? Connect your assistant. Sign in with your MarketCode account; no API key needed.
Reference
What query_sql answers
This is the last resort. If a curated tool or query_semantic can answer the question, it will be cheaper and faster. UK only. You are charged if the query reaches the warehouse and then times out or errors there; a query rejected before it runs — bad SQL, an unreachable schema, a column that does not exist — is free, and the error says what to change.
Inputs
Before you call it
- sql
- The statement must be a single read-only SELECT or WITH over the marts_core, marts_facts, dimensions and location schemas. Bind values with :name placeholders and
paramsrather than interpolating them; the raw ingest schemas are not reachable.
Example
An example call to query_sql
Use the MarketCode tool query_sql with {"sql":"SELECT count(*) AS sales FROM marts_core.transactions WHERE postcode_district = :district","params":{"district":"SE22"},"max_rows":5} and show me the result.{
"error": "HTTP 400",
"detail": "undefined column: column \"postcode_district\" does not exist. Column and table names must exist in the warehouse as written; the semantic endpoint (/property/se…"
}The call failed with these arguments; the status and message are shown rather than an invented body.
Inputs
Arguments query_sql takes
| Name | Type | Required | Description |
|---|---|---|---|
| sql | string | Yes | |
| params | object | No | |
| max_rows | integer | No | Default: 1000 |
Usage
How to run query_sql in your assistant
Ask your assistant in plain English, for example:
"Use the MarketCode tool query_sql for <address or area>.
Show the result and the credits charged."
The arguments the assistant will send, for the example on this page:
{"sql":"SELECT count(*) AS sales FROM marts_core.transactions WHERE postcode_district = :district","params":{"district":"SE22"},"max_rows":5}The connect steps for Claude, ChatGPT, Codex, Cursor and Claude Code are on the MCP page.
Price and licence
What it costs, and where the data comes from
query_sql costs 25 credits per successful call over MCP and over REST, and the two surfaces share one credit balance.
You shape the query, so the price is fixed whatever it returns. A query rejected before it runs is free; you are charged once it reaches the warehouse, even if it then times out or errors there.
Credits are granted on sign-up and bought in packs; the pricing page lists every call.
FAQ
Questions about query_sql
How much does `query_sql` cost?
+
query_sql costs 25 credits per successful call over MCP and over REST, and the two surfaces share one credit balance. You shape the query, so the price is fixed whatever it returns. A query rejected before it runs is free; you are charged once it reaches the warehouse, even if it then times out or errors there.
Which assistants can run `query_sql`?
+
Any MCP client: Claude (claude.ai, Claude Desktop, Claude Code), ChatGPT in developer mode, Codex and Cursor, each documented on the MCP page. You sign in with your MarketCode account over OAuth; there is no key to paste, and the connection is read-only.
Where does the data come from?
+
The answer is computed by MarketCode. Coverage is the UK.
Does `query_sql` change anything?
+
No. The tool is annotated read-only on the server, so it never writes to your data or ours and an assistant can call it without a confirmation step.
Try query_sql in your assistant.
30-minute call. We'll connect your assistant live on a real address.