Alter a table

This Astra DB Serverless feature is currently in public preview. Development is ongoing, and the features and functionality are subject to change. Astra DB Serverless, and the use of such, is subject to the DataStax Preview Terms.

The Data API tables commands are available through HTTP and the clients.

If you use a client, tables commands are available only in client versions 2.0-preview or later. For more information, see Data API client upgrade guide.

Alters a table by doing one of the following:

  • Adding one or more columns to a table

  • Dropping one or more columns from a table

  • Adding automatic embedding generation for one or more vector columns

  • Removing automatic embedding generation for one or more vector columns

You cannot change a column’s type. Instead, you must drop the column and add a new column.

Similarly, you cannot rename a table. Instead, you must drop and recreate the table.

Method signature

  • Python

  • TypeScript

  • Java

  • curl

The following method belongs to the astrapy.Table class.

alter(
  operation: AlterTableOperation | dict[str, Any],
  *,
  row_type: type[Any] = DefaultRowType,
  table_admin_timeout_ms: int,
  request_timeout_ms: int,
  timeout_ms: int,
) -> Table[NEW_ROW]

The following method belongs to the Table class.

async alter<NewWSchema extends SomeRow, NewRSchema extends SomeRow = FoundRow<NewWSchema>>(
  options: AlterTableOptions<SomeRow>
): Table<NewWSchema, PKey, NewRSchema>

The following methods belong to the com.datastax.astra.client.tables.Table class.

Table<T> alter(AlterTableOperation operation)
Table<T> alter(
  AlterTableOperation operation,
  AlterTableOptions options
)
<R> Table<R> alter(
  AlterTableOperation operation,
  AlterTableOptions options,
  Class<R> clazz
)
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE/ASTRA_DB_TABLE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "alterTable": {
    "operation": {
      "add": {
        "columns": {
          "NEW_COLUMN_NAME": "DATA_TYPE",
          "NEW_COLUMN_NAME": "DATA_TYPE"
        }
      }
    }
  }
}'
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE/ASTRA_DB_TABLE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "alterTable": {
    "operation": {
      "drop": {
        "columns": [ "COLUMN_NAME", "COLUMN_NAME" ]
      }
    }
  }
}'
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE/ASTRA_DB_TABLE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "alterTable": {
    "operation": {
      "addVectorize": {
        "columns": {
          "VECTOR_COLUMN_NAME": {
            "provider": "PROVIDER",
            "modelName": "MODEL_NAME",
            "authentication": {
              "providerKey": "API_KEY_NAME"
            },
            "parameters": PARAMETERS
          }
        }
      }
    }
  }
}'
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE/ASTRA_DB_TABLE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "alterTable": {
    "operation": {
      "dropVectorize": {
        "columns": [ "VECTOR_COLUMN_NAME", "VECTOR_COLUMN_NAME" ]
      }
    }
  }
}'

Result

  • Python

  • TypeScript

  • Java

  • curl

Adds or drops columns, or adds or removes a vectorize integration for vector columns. Removing a vectorize integration for a column does not remove the vector embeddings stored in the column.

Returns a new Table instance that represents the table after the modification.

Although the Table instance that you used to perform the alteration will still work, it will not reflect the updated typing if you added or dropped columns. To reflect the new typing, use the row_type parameter.

Adds or drops columns, or adds or removes a vectorize integration for vector columns. Removing a vectorize integration for a column does not remove the vector embeddings stored in the column.

Returns a promise that resolves to a Table instance that represents the table after the modification.

Although the Table instance that you used to perform the alteration will still work, it will not reflect the updated typing if you added or dropped columns. To reflect the new typing, provide the new type of the table to the alter method. For example:

const newTable = await table.alter<NewSchema>({
    operation: {
      add: {
        columns: {
          venue: 'text',
        },
      },
    },
  });

Adds or drops columns, or adds or removes a vectorize integration for vector columns. Removing a vectorize integration for a column does not remove the vector embeddings stored in the column.

Returns a Table<T> instance that represents the table after the schema change.

Although the Table instance that you used to perform the alteration will still work, it will not reflect the updated typing if you added or dropped columns. To reflect the new typing, use the rowClass parameter.

Adds or drops columns, or adds or removes a vectorize integration for columns.

Removing a vectorize integration for a column does not change the column type or remove the vector embeddings stored in the column.

If the command succeeds, the response indicates the success.

Example response:

{
  "status": {
    "ok": 1
  }
}

Parameters

  • Python

  • TypeScript

  • Java

  • curl

Name Type Summary

operation

AlterTableOperation | dict[str, Any]

The alter operation to perform.

Can be one of the following:

  • An AlterTableAddColumns object that specifies the columns to add

  • A dictionary in the form {"add": {"columns": …​}} that specifies the columns to add

  • An AlterTableDropColumns object that specifies the names of the columns to remove

  • A dictionary in the form {"drop": {"columns": …​}} that specifies the names of the columns to remove

  • An AlterTableAddVectorize object that specifies vectorize options and the names of the vector columns for which to add a vectorize integration

  • A dictionary in the form {"addVectorize": {"columns": …​}} that specifies vectorize options and the names of the vector columns for which to add a vectorize integration

  • An AlterTableDropVectorize object that specifies the names of the vector columns from which to remove a vectorize integration

  • A dictionary in the form {"dropVectorize": {"columns": …​}} that specifies the names of the vector columns from which to remove a vectorize integration

row_type

type

This parameter acts a formal specifier for the type checker. If omitted, the resulting Table is implicitly a Table[dict[str, Any]]. If provided, it must match the type hint specified in the assignment. For more information, see Typing support.

table_admin_timeout_ms

int

A timeout, in milliseconds, to impose on the underlying API request. If not provided, the Table defaults apply. This parameter is aliased as request_timeout_ms and timeout_ms for convenience.

Name Type Summary

operation

AlterTableOperations<Schema>

The alter operation to perform.

Can be one of the following:

  • An {add: AddColumnOperation} object that specifies the columns to add

  • A {drop: DropColumnOperation} object that specifies the names of the columns to remove

  • An {addVectorize: AddVectorizeOperation} object that specifies vectorize options and the names of the vector columns for which to add a vectorize integration

  • A {dropVectorize: DropVectorizeOperation} object that specifies the names of the vector columns from which to remove a vectorize integration

timeout?

number | TimeoutDescriptor

The client-side timeout for this operation.

Options (AddColumnOperation):

Name Type Summary

columns

CreateTableColumnDefinitions

The column names, data types, and other settings (if required) for the new columns.

Column are defined in the same way as they are in createTable.

Options (DropColumnOperation):

Name Type Summary

columns

Cols<Schema>[]

The names of the columns to drop from the table.

Options (AddVectorizeOperation):

Name Type Summary

columns

Record<Cols<Schema>, VectorizeServiceOptions>

Specify the names of the vector columns to alter and the vectorize options for each column. The definition is the same as when you define columns in createTable. For more information, see Define a column to automatically generate vector embeddings.

Options (DropVectorizeOperation):

Name Type Summary

columns

Cols<Schema>[]

The names of the columns from which to remove vectorize information.

Name Type Summary

operation

AlterTableOperation

The alter operation to perform.

Can be one of the following:

options

AlterTableOptions

Specialization of the operation, including timeout.

rowClass

Class<?>

An optional new type for the row object. If not provided, the default is Row, which is like a Map object.

Name Type Summary

alterTable

command

The Data API command to modify the configuration of a table in a Serverless (Vector) database. It acts as a container for all the attributes and settings required to modify the table.

operation

object

The alter operation to perform.

Can be one of the following:

  • An object in the form {add: {columns: COLUMN_DEFINITIONS}} that specifies the columns to add

  • An object in the form {drop: {columns: COLUMN_NAMES}} that specifies the names of the columns to remove

  • An object in the form {addVectorize: {columns: VECTORIZE_DEFINITIONS}} that specifies vectorize options and the names of the vector columns for which to add a vectorize integration

  • An object in the form {dropVectorize: {columns: COLUMN_NAMES}} object that specifies the names of the vector columns from which to remove a vectorize integration

operation.add.columns

object

Define columns to add to the table.

The format is the same as when you define columns in createTable.

operation.drop.columns

array

The names of the columns to remove from the table.

operation.addVectorize.columns

object

Provide the name of the target vector column, the dimension, and the vectorize service options.

service is an object containing provider, modelName, and other parameters for the embedding provider integration. Most integrations require authentication in service.authentication.providerKey or through an x-embedding-api-key header. For more information, see Vector type.

operation.dropVectorize.columns

array

The name of the vector column from which you want to remove the embedding provider integration.

Examples

The following examples demonstrate how to alter a table.

Add columns to a table

When you add columns, the columns are defined in the same way as they are when you create a table.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient
from astrapy.info import (
    AlterTableAddColumns,
    ColumnType,
    TableScalarColumnTypeDescriptor,
)

# Get an existing table
client = DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
database = client.get_database("ASTRA_DB_API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Add columns
table.alter(
    AlterTableAddColumns(
        columns={
            "is_summer_reading": TableScalarColumnTypeDescriptor(
                column_type=ColumnType.BOOLEAN,
            ),
            "library_branch": TableScalarColumnTypeDescriptor(
                column_type=ColumnType.TEXT,
            ),
        },
    ),
)
import { DataAPIClient } from '@datastax/astra-db-ts';

// Get an existing table
const client = new DataAPIClient('ASTRA_DB_APPLICATION_TOKEN');
const database = client.db('ASTRA_DB_API_ENDPOINT');
const table = database.table('TABLE_NAME');

// Add columns
(async function () {
  await table.alter({
    operation: {
      add: {
        columns: {
          is_summer_reading: 'boolean',
          library_branch: 'text',
        },
      },
    },
  });
})();
package com.example;

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.tables.definition.rows.Row;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.AlterTableAddColumns;

public class AddColumns {

    public static void main(String[] args) {
        // Get an existing table
        Table<Row> table = new DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
            .getDatabase("ASTRA_DB_API_ENDPOINT")
            .getTable("TABLE_NAME");

        // Add columns
        AlterTableAddColumns alterOperation = new AlterTableAddColumns()
            .addColumnBoolean("is_summer_reading")
            .addColumnText("library_branch");
        table.alter(alterOperation);
    }
}
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/default_keyspace/students" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "alterTable": {
    "operation": {
      "add": {
        "columns": {
          "is_summer_reading": "boolean",
          "library_branch": "text"
        }
      }
    }
  }
}'

Add a vector column and configure an embedding provider integration

When you add a vector column to a table, you can configure an embedding provider integration for the column. The integration will automatically generate vector embeddings for any data inserted into the column.

The configuration depends on the embedding provider. For the configuration and an example for each provider, see Supported embedding providers.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient
from astrapy.info import (
    AlterTableAddColumns,
    TableVectorColumnTypeDescriptor,
    VectorServiceOptions
)

# Get an existing table
client = DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
database = client.get_database("ASTRA_DB_API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Add a vector column and configure an embedding provider integration
table.alter(
    AlterTableAddColumns(
        columns={
            "plot_synopsis": TableVectorColumnTypeDescriptor(
              dimension=MODEL_DIMENSIONS,
              service=VectorServiceOptions(
                  provider="PROVIDER",
                  model_name="MODEL_NAME",
                  authentication={
                      "providerKey": "API_KEY_NAME",
                  },
                  parameters=PARAMETERS
              ),
          ),
        },
    ),
)
import { DataAPIClient } from '@datastax/astra-db-ts';

// Get an existing table
const client = new DataAPIClient('ASTRA_DB_APPLICATION_TOKEN');
const database = client.db('ASTRA_DB_API_ENDPOINT');
const table = database.table('TABLE_NAME');

// Add a vector column and configure an embedding provider integration
(async function () {
  await table.alter({
    operation: {
      add: {
        columns: {
          plot_synopsis: {
            type: 'vector',
            dimension: MODEL_DIMENSIONS,
            service: {
              provider: 'PROVIDER',
              modelName: 'MODEL_NAME',
              authentication: {
                providerKey: 'API_KEY_NAME',
              },
              parameters: PARAMETERS,
            },
          },
        },
      },
    },
  });
})();
package com.example;

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.columns.ColumnDefinitionVector;
import com.datastax.astra.client.tables.definition.rows.Row;
import com.datastax.astra.client.core.vector.SimilarityMetric;
import com.datastax.astra.client.tables.commands.AlterTableAddColumns;
import com.datastax.astra.client.core.vectorize.VectorServiceOptions;

public class AddColumn {

    public static void main(String[] args) {
        // Get an existing table
        Table<Row> table = new DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
            .getDatabase("ASTRA_DB_API_ENDPOINT")
            .getTable("TABLE_NAME");

        // Add a vector column and configure an embedding provider integration
        AlterTableAddColumns alterOperation = new AlterTableAddColumns()
            .addColumnVector(
                "plot_synopsis",
                new ColumnDefinitionVector()
                    .dimension(MODEL_DIMENSIONS)
                    .metric(SimilarityMetric.SIMILARITY_METRIC)
                    .service(
                        new VectorServiceOptions()
                            .provider("PROVIDER")
                            .modelName("MODEL_NAME")
                            .authentication(Map.of("providerKey", "API_KEY_NAME"))
                            .parameters(PARAMETERS)
                    )
            );
        table.alter(alterOperation);
    }
}
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/default_keyspace/students" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "alterTable": {
    "operation": {
      "add": {
        "columns": {
          "plot_synopsis": {
            "type": "vector",
            "dimension": MODEL_DIMENSIONS,
            "service": {
              "provider": "PROVIDER",
              "modelName": "MODEL_NAME",
              "authentication": {
                "providerKey": "API_KEY_NAME"
              },
              "parameters": PARAMETERS
            }
          }
        }
      }
    }
  }
}'

Drop columns from a table

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient
from astrapy.info import AlterTableDropColumns

# Get an existing table
client = DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
database = client.get_database("ASTRA_DB_API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Drop columns
table.alter(
    AlterTableDropColumns(
        columns=["is_summer_reading", "library_branch"],
    ),
)
import { DataAPIClient } from '@datastax/astra-db-ts';

// Get an existing table
const client = new DataAPIClient('ASTRA_DB_APPLICATION_TOKEN');
const database = client.db('ASTRA_DB_API_ENDPOINT');
const table = database.table('TABLE_NAME');

// Drop columns
(async function () {
  await table.alter({
    operation: {
      drop: {
        columns: ["is_summer_reading", "library_branch"],
      },
    },
  });
})();
package com.example;

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.tables.definition.rows.Row;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.AlterTableDropColumns;

public class DropColumns {

    public static void main(String[] args) {
        // Get an existing table
        Table<Row> table = new DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
            .getDatabase("ASTRA_DB_API_ENDPOINT")
            .getTable("TABLE_NAME");

        // Drop columns
        AlterTableDropColumns alterOperation = new AlterTableDropColumns("is_summer_reading", "library_branch");
        table.alter(alterOperation);
    }
}
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/default_keyspace/students" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "alterTable": {
    "operation": {
      "drop": {
        "columns": ["is_summer_reading", "library_branch"]
      }
    }
  }
}'

Add automatic embedding generation to existing vector columns

You can configure an embedding provider integration for an existing vector column. The integration will automatically generate vector embeddings for any data inserted into the column.

The configuration depends on the embedding provider. For the configuration and an example for each provider, see Supported embedding providers.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient
from astrapy.info import (
    AlterTableAddVectorize,
    VectorServiceOptions,
)

# Get an existing table
client = DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
database = client.get_database("ASTRA_DB_API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Configure an embedding provider integration for a vector column
table.alter(
    AlterTableAddVectorize(
        columns={
            "plot_synopsis": VectorServiceOptions(
                provider="PROVIDER",
                model_name="MODEL_NAME",
                authentication={
                    "providerKey": "API_KEY_NAME",
                },
                parameters=PARAMETERS
            ),
        },
    ),
)
import { DataAPIClient } from '@datastax/astra-db-ts';

// Get an existing table
const client = new DataAPIClient('ASTRA_DB_APPLICATION_TOKEN');
const database = client.db('ASTRA_DB_API_ENDPOINT');
const table = database.table('TABLE_NAME');

// Configure an embedding provider integration for a vector column
(async function () {
  await table.alter({
    operation: {
      addVectorize: {
        columns: {
          plot_synopsis: {
            provider: 'PROVIDER',
            modelName: 'MODEL_NAME',
            authentication: {
              providerKey: 'API_KEY_NAME',
            },
            parameters: PARAMETERS,
          },
        },
      },
    },
  });
})();
package com.example;

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.tables.definition.rows.Row;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.AlterTableAddVectorize;
import com.datastax.astra.client.core.vectorize.VectorServiceOptions;

public class AddVectorize {

    public static void main(String[] args) {
        // Get an existing table
        Table<Row> table = new DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
            .getDatabase("ASTRA_DB_API_ENDPOINT")
            .getTable("TABLE_NAME");

        // Configure an embedding provider integration for a vector column
        AlterTableAddVectorize alterOperation =
            new AlterTableAddVectorize()
                .columns(
                    Map.of(
                        "plot_synopsis",
                        new VectorServiceOptions()
                            .provider("PROVIDER")
                            .modelName("MODEL_NAME")
                            .authentication(Map.of("providerKey", "API_KEY_NAME"))
                            .parameters(PARAMETERS)
                            )
                            );
        table.alter(alterOperation);
    }
}
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/default_keyspace/students" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "alterTable": {
    "operation": {
      "addVectorize": {
        "columns": {
          "plot_synopsis": {
            "provider": "PROVIDER",
            "modelName": "MODEL_NAME",
            "authentication": {
              "providerKey": "API_KEY_NAME"
            },
            "parameters": PARAMETERS
          }
        }
      }
    }
  }
}'

Remove automatic embedding generation from vector columns

You can remove automatic embedding generation for one or more vector columns.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient
from astrapy.info import AlterTableDropVectorize

# Get an existing table
client = DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
database = client.get_database("ASTRA_DB_API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Remove automatic embedding generation
table.alter(
    AlterTableDropVectorize(
        columns=["plot_synopsis"],
    ),
)
import { DataAPIClient } from '@datastax/astra-db-ts';

// Get an existing table
const client = new DataAPIClient('ASTRA_DB_APPLICATION_TOKEN');
const database = client.db('ASTRA_DB_API_ENDPOINT');
const table = database.table('TABLE_NAME');

// Remove automatic embedding generation
(async function () {
  await table.alter({
    operation: {
      dropVectorize: {
        columns: ["plot_synopsis"],
      },
    },
  });
})();
package com.example;

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.tables.definition.rows.Row;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.AlterTableDropVectorize;

public class DropColumn {

    public static void main(String[] args) {
        // Get an existing table
        Table<Row> table = new DataAPIClient("ASTRA_DB_APPLICATION_TOKEN")
            .getDatabase("ASTRA_DB_API_ENDPOINT")
            .getTable("TABLE_NAME");

        // Remove automatic embedding generation
        AlterTableDropVectorize alterOperation = new AlterTableDropVectorize("plot_synopsis");
        table.alter(alterOperation);
    }
}
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/default_keyspace/students" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "alterTable": {
    "operation": {
      "dropVectorize": {
        "columns": ["plot_synopsis"]
      }
    }
  }
}'

Client reference

  • Python

  • TypeScript

  • Java

  • curl

For more information, see the client reference.

For more information, see the client reference.

For more information, see the client reference.

Client reference documentation is not applicable for HTTP.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2025 DataStax | 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: +1 (650) 389-6000, info@datastax.com