Skip to main content
StarRocks v3.2.0 introduces the HTTP SQL API for users to perform various types of queries using HTTP. Currently, this API supports SELECT, SHOW, EXPLAIN, and KILL statements. Syntax using the curl command:

Request message

Request line

  • Query data across databases in a specified catalog. If a table is used in the SQL query, you must prefix the table name with its database name.
  • Query data from a specified catalog and database.

Authentication method

Basic authentication is used, that is, enter the username and password for credentials (-u '<username>:<password>'). If no password is set for the username, you can pass in only <username>: and leave the password empty. For example, if the root account is used, you can enter -u 'root:'. A token issued by your identity provider is also accepted, if a JWT or OAuth 2.0 security integration is configured:
No username is sent with a token: the database takes it from the claim named by the integration’s principal_field. For which credential each kind of user can send, see Where each authentication method works.

Request body

Request header

This header indicates that the request body is a JSON string.

Response message

Status code

  • 200: HTTP request succeeded and the server is normal before data is sent to the client.
  • 4xx: HTTP request error, which indicates a client error.
  • 500 Internal Server Error: HTTP request succeeded but the server encounters an error before data is sent to the client.
  • 503: HTTP request succeeded but the FE cannot provide service.

Response header

content-type indicates the format of the response body. Newline delimited JSON is used, which means the response body consists of multiple JSON objects that are separated by \n.

Response body

Failed before the request is sent

Request fails on the client side or the server encounters an error before it returns data to the client. The response body is in the following format, where msg is the error information.

Failed after the request is sent

Part of the result is returned and the HTTP status code is 200. Data sending is suspended, the connection is closed, and the error is logged.

Succeeded

Each row in the response message is a JSON object. JSON objects separated by \n.
  • For a SELECT statement, the following JSON objects are returned.
  • For a SHOW statement, meta, data, and statistics are returned.
  • For the EXPLAIN statement, an explain object is returned to show detailed execution plan of the query.
The following example uses \n as the separator. The database transmits data using HTTP chunked mode. Each time the FE obtains a data chunk, it streams the data chunk to the client. The client can parse data by row, which eliminates the need for data caching and the need to wait for the entire data, reducing memory consumption for the client.

Examples

Run a SELECT query

  • Query data from a internal table (catalog_name is default_catalog).
    Result:
  • Query data from an Iceberg table.
    Result:

Cancel a query

To cancel a query that run an unexpected long time, you can close the connection. The database will cancel this query when it detects the connection is closed. You can also call KILL connectionId to cancel this query. For example:
You can obtain the connectionId from the response body or by calling SHOW PROCESSLIST. For example:

Run a query with a session variable set for this query