Palbase Machines · API
/databases/{name}/sqlRun a statement against a database
Runs one statement against the database and answers its columns and its first rows, as Studio's console shows them: in a transaction that takes no writes — Postgres refuses one (400 query_failed, sqlstate 25006) — always rolled back, as the database's owner, sent as one statement of the extended protocol (two are refused: 42601), within 15 s (57014) and 5 s for a lock (55P03). A statement Postgres refuses is answered 400 query_failed with its message and SQLSTATE. Each value as JSON: numbers, booleans and null as such, a timestamp in RFC 3339, numeric as a string, bytea as \x and its hex, json and jsonb as the JSON they hold, an array as an array, anything else its text form. A sleeping database is woken, the call held a few seconds for it (503 database_waking with Retry-After past that); one being brought back to a moment, or that cannot start, is refused (409). A database runs a few of the console's calls at once (429 too_many_queries past them).
Called by your server, with the project's secret key.
Path
namestring · requiredThe database's name: lowercase letters, digits and dashes, starting with a letter and not ending with a dash, 32 at most.Request body
sqlstring · requiredOne statement, 64 KiB at most.limitinteger · optionalHow many of its rows to answer, 1 to 1000; a value outside that range is refused.curl -X POST "https://<your-ref>.palbase.studio/databases/<name>/sql" \
-H "apikey: $PALBASE_SECRET_KEY" \
-H "content-type: application/json" \
-d '{"sql":"string"}'Responses
200What the statement answered
400The statement was refused: by Postgres (`query_failed`, with its SQLSTATE), or as it was asked
401Missing or invalid API key
403Not the project's secret key; or the request requires elevated owner authentication (`owner_only`, `insufficient_user_authentication`).
404The project has no database of this name
409The project already has a database of this name (or one being purged), the environment as many databases as it may, or no room left for this one; a password change is still on its way to the database; or a machine is given the database; or the database is moving to another size, cannot start (a change of its size waits for a restore that brings it back), holds more than the one asked, or would have too few connections for the copies of the machines given it; or, to the console, the database is being brought back to a moment, cannot start, or has run its awake hours for the month
429Over the project's request limit, or its machine time for this period is used up
503Temporarily unavailable; retrying is safe after Retry-After
defaultAn error: the envelope names it (`error`) and explains it (`error_description`).
Operation QueryDatabase of machines's contract.