Queries data by using SQL statements.
Request syntax
message SQLQueryRequest {
required string query = 1;
optional SQLPayloadVersion version = 2;
optional int64 sql_version = 3;
}
Parameter | Type | Required | Description |
query | string | Yes | The SQL statement. |
version | No | The encoding format of data returned. | |
sql_version | int64 | No | The version of the SQL protocol. Valid values:
|
Response syntax
message SQLQueryResponse {
repeated TableConsumedCapacity consumes = 1;
optional bytes rows = 2;
optional SQLPayloadVersion version = 3;
optional SQLStatementType type = 4;
}
Parameter | Type | Required | Description |
consumes | repeated TableConsumedCapacity | Yes | The number of capacity units (CUs) that are consumed by the operation. For more information, see CU consumption. |
rows | bytes | No | The row data that is returned. The value is encoded in the format that you specified. |
version | Yes | The encoding format of data returned. | |
type | Yes | The type of SQL statements. |
Use Tablestore SDKs
CU consumption
You are not charged for using the SQL query feature. However, when you use the SQL query feature, you are charged fees that are generated by operations such as table scanning and index-based queries.
The read throughput that is consumed when you execute a single SQL statement is the sum of read throughput that is consumed when specific operations are performed on the table and the index. The number of consumed read CUs is rounded up from the calculation result of the following formula: Number of consumed read CUs = (Size of data in all primary key columns of the row + Size of data in the attribute columns that are read)/4 KB.
If the request times out and the results are undefined, CUs may or may not be consumed.
If an HTTP status code 5xx is returned, which indicates that an internal error occurred, the operation does not consume CUs. If other errors are returned, one read CU is consumed.