Gateway

Execute SQL query

Changed on

Execute a single SQL query or a batch of queries against a PostgreSQL branch.

Authentication: send the branch's PostgreSQL connection string in the Connection-String header. The control-plane API key (Bearer token) is not accepted on the gateway host.

Routing: the target branch, region, and endpoint type are taken from the hostname embedded in the connection string, which must match the request host. See the Connection-String security scheme for the host format.

Single query: provide query (and optional params) at the top level.

Batch: provide queries as an array of query objects, or send the request body as a JSON array. Batch queries execute within a single transaction.

Errors: PostgreSQL errors return 400 with their SQLSTATE in code and their diagnostic fields. A 503 means the gateway could not reach the database: 08001 when a connection cannot be established and 08006 when an established connection fails. A 503 does not guarantee that replaying a write is safe: a connection failure can leave its outcome unknown.

post/sql

Request

  • Base URL
    https://my-branch.us-east-1.xata.tech
  • Auth
    API key in header Connection-String

Headers

Array-Mode'true' | 'false'

When true, return rows as arrays instead of objects.

Raw-Text-Output'true' | 'false'

When true, return all values as strings without type conversion.

Batch-Isolation-Level'ReadCommitted' | 'ReadUncommitted' | 'RepeatableRead' | 'Serializable'

Transaction isolation level for batch queries.

Batch-Read-Only'true' | 'false'

When true, execute the batch transaction in read-only mode.

Batch-Deferrable'true' | 'false'

When true, execute the batch transaction in deferrable mode.

Request body

querystring

SQL query to execute (single query mode).

arrayModeboolean

Override array mode for this query (single query mode only).

Response

Query executed successfully

OR

Changes

    • info

      added the non-success response with the status

    • breaking

      the //////// response's property format changed from int32 to int64 for status

    • breaking

      the //////// response's property format changed from int32 to int64 for status

    • breaking

      the ////// response's property format changed from int32 to int64 for status

    • breaking

      the ////// response's property format changed from int32 to int64 for status