Retrieves table schema information, including field names and field types, by executing the DESCRIBE statement.
For the full DESCRIBE statement syntax, see Query information about tables.
Prerequisites
Before you begin, ensure that you have:
A Tablestore client initialized. For more information, see Initialize a Tablestore client
Usage notes
The SQL query feature requires Tablestore SDK for .NET V5.0.0 or later.
For version details, see Version history of Tablestore SDK for .NET .
Parameters
|
Parameter |
Description |
|
query |
The SQL statement to run. To query table information, use |
Examples
The following example runs the describe test_table statement and prints the schema and each row of the result set. Each row contains six columns in this order: field name, field type, null constraint, default value, primary key flag, and partition key flag.
/// <summary>
/// Query information about a table.
/// </summary>
/// <param name="otsClient"></param>
public static void DescribeTable(OTSClient otsClient)
{
SQLQueryRequest sqlQueryRequest = new SQLQueryRequest("describe test_table");
SQLQueryResponse sqlQueryResponse = otsClient.SQLQuery(sqlQueryRequest);
// Print the table schema as JSON.
SQLTableMeta sqlTableMeta = sqlQueryResponse.GetSQLResultSet().GetSQLTableMeta();
Console.WriteLine(JsonConvert.SerializeObject(sqlTableMeta.GetSchema()));
// Iterate over the result set. Each row contains six columns:
// index 0: field name, 1: field type, 2: null constraint,
// 3: default value, 4: primary key flag, 5: partition key flag.
ISQLResultSet resultSet = sqlQueryResponse.GetSQLResultSet();
while (resultSet.HasNext())
{
ISQLRow row = resultSet.Next();
Console.WriteLine(row.GetString(0) + " " + row.GetString(1) + " " + row.GetString(2) + " " +
row.GetString(3) + " " + row.GetString(4) + " " + row.GetString(5));
}
}