Skip to content
EleforkDocs
Internal preview. Elefork is not publicly available yet; APIs and hostnames may change.

Run SQL on a branch

POST
/v1/branches/{id}/sql
curl --request POST \
--url https://api.elefork.com/v1/branches/example/sql \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '{ "sql": "example", "database": "postgres", "role": "postgres", "max_rows": 1000 }'

Runs a script (one or more statements, simple query protocol) as role in database, through the gateway like any client: a paused branch is woken, and the session counts as activity. Each request is its own session (no transaction spans requests); statements time out after 30 s. Postgres errors are returned as error with status 200, after the results of the statements that ran before the failing one. Rows beyond max_rows per result, and bytes beyond 4 MiB in total, are dropped (truncated). Values are in Postgres text format; null is NULL.

id
required
string
Media typeapplication/json
object
sql
required
string
>= 1 characters <= 1048576 characters
database
string
default: postgres
role
string
default: postgres
max_rows
integer
default: 1000 >= 1 <= 1000

Results, one per statement

Media typeapplication/json
object
results
required
Array<object>
object
columns
required
Array<object>
object
name
required
string
type
required
string
rows
required
Array<Array>
command_tag
required
string
row_count
required

Rows returned or affected

integer
truncated
required
boolean
duration_ms
required
integer
error
object
sqlstate
required
string
message
required
string
detail
string
hint
string
position

1-based character offset in the script

integer

Example generated

{
"results": [
{
"columns": [
{
"name": "example",
"type": "example"
}
],
"rows": [
[
"example"
]
],
"command_tag": "example",
"row_count": 1,
"truncated": true
}
],
"duration_ms": 1,
"error": {
"sqlstate": "example",
"message": "example",
"detail": "example",
"hint": "example",
"position": 1
}
}

Error

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string

Example

{
"error": {
"code": "not_found"
}
}

Error

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string

Example

{
"error": {
"code": "not_found"
}
}

Error

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string

Example

{
"error": {
"code": "not_found"
}
}

Error

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string

Example

{
"error": {
"code": "not_found"
}
}

Error

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string

Example

{
"error": {
"code": "not_found"
}
}

Error

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string

Example

{
"error": {
"code": "not_found"
}
}

Error

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string

Example

{
"error": {
"code": "not_found"
}
}

Error

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string

Example

{
"error": {
"code": "not_found"
}
}

Temporarily unavailable; retry after the Retry-After seconds. Codes: database_unavailable (the metadata database is failing over) and cube_admission (a compute node runs a sandbox shim below the platform minimum, so creates, forks, checkpoints and resets are refused until it is upgraded).

Media typeapplication/json
object
error
required
object
code
required
string
message
required
string

Example

{
"error": {
"code": "not_found"
}
}
Retry-After
integer