Get a table (Go)

Gets a reference to a table for use with the Data API clients.

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 a Table object that corresponds to the specified table name.

This method returns a Table object even for collections that don’t exist.

Parameters

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

Method signature
func (d *Db) Table(
  name string,
  opts ...options.GetTableOption
) *Table
Name Type Summary

name

string

The name of the table.

opts

GetTableOption

Optional. The options for this method.

Methods of the GetTableOption builder
Method Summary

SetKeyspace(v string)

Optional if you specified a working keyspace when you created the Db object. The keyspace containing the table.

Default: The working keyspace set when you created the Db object, if one was provided.

UpdateAPIOptions(v …​APIOption)

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

Examples

The following examples demonstrate how to get a table.

Get a table

package main

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

func main() {
	// Get a database
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	// Get a table
	database.Table("TABLE_NAME")
}

Get a table and specify typing

The Go client doesn’t support typing when you instantiate a Table object. Instead, you specify the row type when you perform operations like inserting or finding rows.

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