You can execute the show tables statement to list the names of tables in the current database.
Note For more information about the show tables statement, see List table names.
Prerequisites
- A Tablestore client is initialized. For more information, see Initialization.
- A mapping table is created. For more information, see Create tables and mapping tables.
Parameters
Parameter | Description |
---|---|
query | The SQL statement. Configure the parameter based on the required feature. |
Examples
Execute the show tables
statement to list the names of tables.
func showTable(client *tablestore.TableStoreClient) {
// Create a SQL request.
request := &tablestore.SQLQueryRequest{Query: "show tables"}
// Obtain the response to the SQL request.
response, err := client.SQLQuery(request)
if err != nil {
panic(err)
}
// Obtain the schema of the returned results of the SQL request.
columns := response.ResultSet.Columns()
fmt.Printf("response table schema: %v\n", columns)
// Use SQL ResultSet to obtain all returned results of the SQL request.
fmt.Println("response resultset:")
resultSet := response.ResultSet
for resultSet.HasNext() {
row := resultSet.Next()
tableName, err := row.GetString(0)
if err != nil {
panic(err)
}
fmt.Println(tableName)
}
}
Sample output:
response table schema: [Tables_in_$instanceName:STRING]
response resultset:
test_table