List table metadata (Go)

Gets information about the tables in a keyspace.

Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart.

Result

Returns an unordered slice of TableDescriptor structs that describe each table.

Parameters

Use the ListTables method, which belongs to the Db type.

Method signature
func (d *Db) ListTables(
  ctx context.Context,
  opts ...options.ListTablesOption
) ([]results.TableDescriptor, error)
Name Type Summary

ctx

context.Context

The context for the operation.

opts

…​options.ListTablesOption

Optional. A builder to generate options for this operation. See Methods of the ListTablesOption builder for more details.

Methods of the ListTablesOption builder
Method Summary

SetKeyspace(v string)

Optional. The keyspace to inspect.

For an example, see List table metadata and specify the keyspace.

Default: The working keyspace for the database. This is default_keyspace unless you set a different working keyspace when you created the Db object.

UpdateAPIOptions(v …​APIOption)

Optional. General API options for this operation, including the timeout.

Examples

The following examples demonstrate how to list table metadata.

List table metadata

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get a database
	client := astra.NewClient()

	database := client.Database(
		"API_ENDPOINT",
		options.API().SetToken("APPLICATION_TOKEN"),
	)

	// List table metadata
	tables, err := database.ListTables(ctx)

	if err != nil {
		log.Fatal(err)
	}

	output, err := json.Marshal(tables)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(output))
}

List table metadata and specify the keyspace

By default, this method uses the working keyspace of your database. If you want to use a different keyspace, you must specify the keyspace.

package main

import (
	"context"
	"encoding/json"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get a database
	client := astra.NewClient()

	database := client.Database(
		"API_ENDPOINT",
		options.API().SetToken("APPLICATION_TOKEN"),
	)

	// List table metadata
	tables, err := database.ListTables(
		ctx,
		options.ListTables().SetKeyspace("KEYSPACE_NAME"),
	)

	if err != nil {
		log.Fatal(err)
	}

	output, err := json.Marshal(tables)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(output))
}

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | Privacy policy | Terms of use Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: Contact IBM