Semaphor
Query

Execute a SQL query

Runs a SQL query against a connection in your project and returns the result rows as JSON.

The connection identified by connectionId must belong to the same project as the access token. Any security policies assigned to the token (row-level, column-level, and schema-level security) are applied automatically before the result is returned.

Python post-processing

If you include pythonCode, execution follows this order:

StageWhat happens
1Semaphor runs the SQL query against the connection
2Security policies and row limits are applied to the result
3The filtered rows are passed into a server-side Python environment as data
4If your code sets a variable called result, that value is returned; otherwise the original rows are returned

Inside the Python environment:

  • data is a list of dictionaries (one per row)
  • Anything printed to stdout is captured and returned in the output field
  • Assign your transformed rows to result to replace the default response

Example:

import pandas as pd

df = pd.DataFrame(data)
result = df.to_dict("records")
POST
/api/v1/sql

Authorization

BearerAuth
AuthorizationBearer <token>

A project-scoped access token. Generate one via the Token API.

In: header

Request Body

application/json

TypeScript Definitions

Use the request body type in TypeScript.

Response Body

application/json

application/json

application/json

application/json

application/json

curl -X post "https://semaphor.cloud/api/v1/sql" \  -H "Content-Type: application/json" \  -d '{    "connectionId": "conn_sales",    "sql": "select\n  order_id,\n  amount,\n  created_at\nfrom orders\nwhere status = \'paid\'\n"  }'

{
  "records": [
    {
      "order_id": 1,
      "amount": 12.3
    },
    {
      "order_id": 2,
      "amount": 44.1
    }
  ],
  "rowLimitExceeded": false
}

{
  "error": "string",
  "requestId": "string",
  "details": "string",
  "warnings": [
    "string"
  ]
}
{
  "error": "string",
  "requestId": "string",
  "details": "string",
  "warnings": [
    "string"
  ]
}
{
  "error": "string",
  "requestId": "string",
  "details": "string",
  "warnings": [
    "string"
  ]
}
{
  "error": "string",
  "requestId": "string",
  "details": "string",
  "warnings": [
    "string"
  ]
}