HTTP SQL API
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:
curl -X POST 'http://<fe_ip>:<fe_http_port>/api/v1/catalogs/<catalog_name>/databases/<database_name>/sql' \
-u '<username>:<password>' -d '{"query": "<sql_query>;", "sessionVariables":{"<var_name>":<var_value>}}' \
--header "Content-Type: application/json"
Request messageβ
Request lineβ
POST 'http://<fe_ip>:<fe_http_port>/api/v1/catalogs/<catalog_name>/databases/<database_name>/sql'
| Field | Description |
|---|---|
| fe_ip | FE node IP address. |
| fe_http_port | FE HTTP port. |
| catalog_name | The catalog name. In v3.2.0, you can use this API to query only StarRocks internal tables, which means <catalog_name> can only be set to default_catalog. Since v3.2.1, you can use this API to query tables in external catalogs. |
| database_name | The database name. If no database name is specified in the request line and a table name is used in the SQL query, you must prefix the table name with its database name, for example, database_name.table_name. |
-
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.
POST /api/v1/catalogs/<catalog_name>/sql -
Query data from a specified catalog and database.
POST /api/v1/catalogs/<catalog_name>/databases/<database_name>/sql
Authentication methodβ
Authorization: Basic <credentials>
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:'.
Request bodyβ
-d '{"query": "<sql_query>;", "sessionVariables":{"<var_name>":<var_value>}}'
| Field | Description |
|---|---|
| query | The SQL query, in STRING format. Only SELECT, SHOW, EXPLAIN, and KILL statements are supported. You can run only one SQL query for an HTTP request. |
| sessionVariables | The session variable you want to set for the query, in JSON format. This field is optional. Default is empty. The session variable you set takes effect for the same connection and becomes ineffective when the connection is closed. |
Request headerβ
--header "Content-Type: application/json"
This header indicates that the request body is a JSON string.