All Products
Search
Document Center

Tablestore:Query information about tables

Last Updated:May 24, 2024

You can execute the DESCRIBE statement to query the information about tables, such as the field names and field types.

Note

For more information about the DESCRIBE statement, see Query information about tables.

Prerequisites

Usage notes

Tablestore SDK for Java V5.13.0 or later supports the SQL query feature. Before you use the SQL query feature, make sure that Tablestore SDK for Java V5.13.0 or later is obtained. For more information about the version history of Tablestore SDK for Java, see Version history of Tablestore SDK for Java.

Parameters

Parameter

Description

query

The SQL statement. Configure the parameter based on the required feature.

Example

The following sample code provides an example on how to execute the describe test_table statement to query the information about test_table:

private static void getTableDesc(SyncClient client) {
    // Create an SQL request. 
    SQLQueryRequest request = new SQLQueryRequest("describe test_table");

    // Obtain the response to the SQL request. 
    SQLQueryResponse response = client.sqlQuery(request);
    // Obtain the schema of the returned results of the SQL request. 
    SQLTableMeta tableMeta = response.getSQLResultSet().getSQLTableMeta();
    System.out.println("response table schema: " + tableMeta.getSchema());

    // Use SQL ResultSet to obtain all returned results of the SQL query statement. 
    System.out.println("response resultset:");
    SQLResultSet resultSet = response.getSQLResultSet();
    while (resultSet.hasNext()) {
        SQLRow row = resultSet.next();
        System.out.println(row.getString(0) + ", " + row.getString(1) + ", " +
                           row.getString(2) + ", " + row.getString(3) + ", " +
                           row.getString(4) + ", " + row.getString(5));
    }
}

Sample response:

response table schema: [Field:STRING, Type:STRING, Null:STRING, Key:STRING, Default:STRING, Extra:STRING]
response resultset:
pk, varchar(1024), NO, PRI, null,
long_value, bigint(20), YES, , null,
double_value, double, YES, , null,
string_value, mediumtext, YES, , null,
bool_value, tinyint(1), YES, , null,

References

  • To use a mapping table to query data that meets specific conditions, execute the SELECT statement. For more information, see Query data.

  • To update the attribute column of the mapping table after the attribute column of the data table is changed, execute the ALTER TABLE statement. For more information, see Update attribute columns of mapping tables.

  • To delete a mapping table, execute the DROP MAPPING TABLE statement. For more information, see Delete mapping tables.