API Reference
Queries
Execute immediate (synchronous) and background (asynchronous) SQL queries over HTTP.
Query API Reference
The query API allows executing arbitrary SQL queries with parameterization, automatic session pooling, and optional background execution.
Immediate Queries (Synchronous)
Run SQL statements immediately and receive results directly in the HTTP response.
- Endpoint:
POST /queryorPOST /query/run - Headers:
x-api-key,x-database,content-type: application/json
Request Body
{
"query": "SELECT id, title, price FROM public.products WHERE category = $1 AND in_stock = $2",
"parameters": ["electronics", true],
"options": {
"arrayMode": false,
"lossless": true
}
}| Field | Type | Required | Description |
|---|---|---|---|
query | string | Yes | The SQL statement to execute. |
parameters | array | No | Bound parameters matching $1, $2, ... placeholders. Alias: params. |
options | object | No | Serialization options (arrayMode, lossless, fullResults). |
Response (200 OK)
{
"success": true,
"data": {
"database": "store",
"command": "SELECT",
"rowCount": 1,
"rows": [
{
"id": 101,
"title": "Noise Cancelling Headphones",
"price": "199.99"
}
],
"fields": [
{"name": "id", "dataTypeID": 20},
{"name": "title", "dataTypeID": 25},
{"name": "price", "dataTypeID": 1700}
],
"durationMs": 4.12
}
}Connection Lifecycle & Reset
- The gateway checks out a pooled connection scoped to the API key's provisioned role.
- Connection acquisition waits up to
database.pool.checkoutTimeoutMillis(default: 10 seconds). - The gateway applies
statement_timeout = 30000(30 seconds) at session checkout. - After statement execution, the gateway automatically rolls back any active transaction and executes
DISCARD ALLto purge temporary tables, prepared statements, and session variables before returning the connection to the pool. - If the connection fails verification or experiences a timeout, it is closed and replaced.
Asynchronous Queries (Background Polling)
For long-running queries, analytical reporting, or heavy calculations that exceed standard HTTP invocation deadlines.
1. Submit Asynchronous Query
Pass "type": "async" in the request body to POST /query:
curl -X POST http://localhost:8080/query \
-H 'x-api-key: <api-key>' \
-H 'x-database: analytics' \
-H 'content-type: application/json' \
-d '{
"type": "async",
"query": "SELECT date_trunc(\"month\", created_at), sum(total) FROM orders GROUP BY 1",
"parameters": []
}'Response (202 Accepted)
{
"success": true,
"data": {
"queryId": "qry_01jk94b...",
"status": "running",
"finalized": false
}
}The response includes a Location: /query/qry_01jk94b... header.
2. Poll Query Status
Poll the status endpoint using the returned query ID:
curl http://localhost:8080/query/qry_01jk94b... \
-H 'x-api-key: <api-key>' \
-H 'x-database: analytics'Alternatively, pass the query ID via header x-query-id: qry_01jk94b... or query parameter ?queryId=qry_01jk94b... to GET /query.
While Running (finalized: false)
{
"success": true,
"data": {
"queryId": "qry_01jk94b...",
"status": "running",
"finalized": false
}
}Once Completed (finalized: true)
{
"success": true,
"data": {
"queryId": "qry_01jk94b...",
"status": "completed",
"finalized": true,
"outcome": {
"status": 200,
"payload": {
"success": true,
"data": {
"rowCount": 12,
"rows": [...]
}
}
}
}
}3. Delete Query Record
Once you have consumed the result, delete the record from storage:
curl -X DELETE http://localhost:8080/query/qry_01jk94b... \
-H 'x-api-key: <api-key>' \
-H 'x-database: analytics'- If deleted successfully: Returns
200 OK. SubsequentGETrequests return404 QUERY_NOT_FOUND. - Attempting to delete a running query returns
409 QUERY_IN_PROGRESS.
Limits & Behavior
- PostgreSQL Statement Timeout: Async queries receive a 5-minute statement timeout (compared to 30 seconds for immediate queries).
- Concurrency: Each gateway process permits up to 32 concurrent asynchronous queries. Exceeding this returns
503 QUERY_QUEUE_FULL. - Durability: Stored async outcomes survive gateway restarts. They are stored in
http_postgres_gateway.async_queriesin the administrative database and pruned automatically based ontransactions.retentionDays.
