Execute a read-only SQL query
POST /query
Executes a SQL query against MotherDuck and returns results. Only
read-only statements are allowed: SELECT, PRAGMA, DESCRIBE,
SHOW, WITH.
Each tenant has its own database (warehouse_{bucket}). Use the
optional database field to switch to a specific tenant database
before querying — otherwise queries run against the default
connection (md:).
19 tables available per tenant: person, organisation, member, payment, message, membership_type, ticket_type, booking, ticket, attendee, activity, bank_account, badge, connection, evidence, pledge, grant, group, group_member.
Cross-table joins use uri columns (e.g. member.member = person.uri).
Authorizations
Section titled “Authorizations ”Request Body required
Section titled “Request Body required ”object
SQL statement to execute. Only read-only statements are allowed: SELECT, PRAGMA, DESCRIBE, SHOW, WITH.
Example
SELECT * FROM person LIMIT 10Optional database name to switch to before executing the query.
Use warehouse_{bucket} format (hyphens replaced with underscores).
If omitted, queries run against the default connection.
Example
warehouse_exampleExamples
Simple SELECT with database
{ "sql": "SELECT * FROM person LIMIT 10", "database": "warehouse_example"}Join members to persons
{ "sql": "SELECT m.membership_type, p.first_name, p.last_name FROM member m JOIN person p ON m.member = p.uri LIMIT 10", "database": "warehouse_example"}Describe a table
{ "sql": "DESCRIBE person", "database": "warehouse_example"}Responses
Section titled “ Responses ”Query executed successfully
object
object
Column names from the result set.
Example
[ "uid", "first_name", "last_name"]Result rows. Each row is an array of values matching the columns.
Example
[ [ "abc123", "Jane", "Smith" ]]Example
{ "data": { "columns": [ "uid", "first_name", "last_name" ], "rows": [ [ "abc123", "Jane", "Smith" ] ] }}Invalid or disallowed SQL statement
object
object
Machine-readable error code.
Example
unauthorizedHuman-readable error message.
Example
Authentication requiredExamples
Missing sql field
{ "error": { "code": "bad_request", "message": "Missing 'sql' field" }}Non-SELECT statement
{ "error": { "code": "bad_request", "message": "Only SELECT, PRAGMA, DESCRIBE, SHOW, and WITH statements are allowed (got DROP)" }}Authentication required
object
object
Machine-readable error code.
Example
unauthorizedHuman-readable error message.
Example
Authentication requiredExample
{ "error": { "code": "unauthorized", "message": "Authentication required" }}Internal server error
object
object
Machine-readable error code.
Example
unauthorizedHuman-readable error message.
Example
Authentication requiredExample
{ "error": { "code": "schema_error", "message": "Schema application failed" }}