Skip to content

Data and SQL endpoints

The Data API's operations and headers, and the SQL endpoints.

Applies to EngineCloud
View as Markdown
On this page
  1. The Data API
  2. SQL

The Data API

OperationPath
readGET /rest/v1/{table} (HEAD for the headers and the count only)
insert / upsertPOST /rest/v1/{table}
updatePATCH /rest/v1/{table}?{filters}
deleteDELETE /rest/v1/{table}?{filters}
call a functionPOST /rest/v1/rpc/{function} with the arguments as a JSON object
several operations in one transactionPOST /rest/v1/transaction
the API descriptionGET /rest/v1/ (OpenAPI 3.1; a signed-in user, a PAT, a machine token or a secret key)
Query parameterExample
selectid,total,customer:customers(name)
a filterstatus=eq.paid, total=gte.50000, tags=cs.{pan}, name=ilike.*masa*, deleted_at=is.null, not.status=eq.void
or, andor=(status.eq.paid,total.gt.100000)
ordercreated_at.desc.nullslast,id
limit, offset20, 40
on_conflictemail (with an upsert)
columnsnote,total (with an insert: the columns to take from the body)

Operators: eq, neq, gt, gte, lt, lte, like, ilike, in, is, cs, cd, ov, fts, plfts, phfts, wfts, each optionally after not..

HeaderValues
Preferreturn=minimal|representation, count=exact|planned|estimated, resolution=merge-duplicates|ignore-duplicates, missing=default
Range / Range-Unit0-19 / items
Accept-Profile / Content-Profilea schema name
Accept: application/vnd.pgrst.object+jsonone object instead of a list; 406 not_single when the result has another number of rows
Content-Range (response)0-19/1324

A transaction:

Field of an operation
nameoptional; later operations use its results with {"$ref": "<name>.<field>"}
methodGET, POST, PATCH or DELETE
table, schemathe table, and its schema when it is not the default
querya PostgREST query, as a string or an object; object values may be $refs
bodyrows (POST) or values (PATCH); any value may be a $ref
incrementPATCH only: { "col": n } adds n in the database
expect{ rows }, { min } or { max }: rows returned or changed
on_errorrollback (default) or continue
returningtrue (default) returns the rows

The answer is { "results": [ { "op", "name", "count", "rows" } … ] }, with { "op", "name", "error" } for an operation that failed with on_error: "continue". See The Data API.

Errors: invalid_query, invalid_body, empty_update, filter_required (update or delete without filters), table_not_found, column_not_found, function_not_found, relationship_not_found, permission_denied (a grant or a policy said no), statement_timeout, expectation_failed, insufficient_scope, and the database’s own errors. Every code: Errors and limits.

SQL

EndpointDoes
POST /sql/v1/query { query, params?, read_only?, row_limit?, timeout_ms? }runs SQL; several statements give several results; params only with one statement
POST /sql/v1/transaction { statements: [{ sql, params?, expect? }], read_only?, timeout_ms? }up to 100 statements in one transaction, each in a savepoint; answers { results, duration_ms, row_limit }
GET /sql/v1/migrationsapplied migrations: version, scope (engine or project), name, checksum, applied_at, applied_by
POST /sql/v1/migrations { name, sql }applies one in a transaction; 201, or 409 migration_checksum_mismatch
GET /sql/v1/schema?schemas=publictables, columns, keys, relations, policies (and whether row-level security is on), functions as JSON
FieldDefaultLimit
row_limit5 0005 000; more answers row_limit_capped: 5000
timeout_ms15 00060 000

Each result has command, columns, rows, row_count (every row the statement returned or changed) and truncated when more rows came back than row_limit.

Who may call: a secret key, a token with sql:read (read-only queries, schema and the migrations list) or sql:write (everything), or the project’s owner from the console. See SQL and migrations.

  1. The Data API
  2. SQL

    Search pages, sections and terms