创建启用自定义生存时间(TTL)设置的表 - Amazon Keyspaces(Apache Cassandra 兼容)
Amazon Web Services 文档中描述的 Amazon Web Services 服务或功能可能因区域而异。要查看适用于中国区域的差异,请参阅 中国的 Amazon Web Services 服务入门 (PDF)

本文属于机器翻译版本。若本译文内容与英语原文存在差异,则一律以英文原文为准。

创建启用自定义生存时间(TTL)设置的表

要在不对整个表启用 TTL 默认设置的情况下使用可应用于行和列的生存时间自定义设置创建新表,可以使用以下命令。

注意

如果创建启用了 ttl 自定义设置的表,则以后将无法禁用该设置。

Cassandra Query Language (CQL)
通过 CQL 使用自定义 TTL 设置创建新表
  • CREATE TABLE my_keyspace.my_table (id int primary key) WITH CUSTOM_PROPERTIES={'ttl':{'status': 'enabled'}};
CLI
通过 Amazon CLI 使用自定义 TTL 设置创建新表
  1. 您可以使用以下命令创建启用 TTL 的新表。

    aws keyspaces create-table --keyspace-name 'myKeyspace' --table-name 'myTable' \ --schema-definition 'allColumns=[{name=id,type=int},{name=name,type=text}, {name=date,type=timestamp}],partitionKeys=[{name=id}]' \ --ttl 'status=ENABLED'
  2. 要确认为表启用了 TTL,可以使用以下语句。

    aws keyspaces get-table --keyspace-name 'myKeyspace' --table-name 'myTable'

    语句输出应类似于以下示例。

    { "keyspaceName": "myKeyspace", "tableName": "myTable", "resourceArn": "arn:aws:cassandra:us-east-1:123SAMPLE012:/keyspace/myKeyspace/table/myTable", "creationTimestamp": "2024-09-02T10:52:22.190000+00:00", "status": "ACTIVE", "schemaDefinition": { "allColumns": [ { "name": "id", "type": "int" }, { "name": "date", "type": "timestamp" }, { "name": "name", "type": "text" } ], "partitionKeys": [ { "name": "id" } ], "clusteringKeys": [], "staticColumns": [] }, "capacitySpecification": { "throughputMode": "PAY_PER_REQUEST", "lastUpdateToPayPerRequestTimestamp": "2024-09-02T11:18:55.796000+00:00" }, "encryptionSpecification": { "type": "AWS_OWNED_KMS_KEY" }, "pointInTimeRecovery": { "status": "DISABLED" }, "ttl": { "status": "ENABLED" }, "defaultTimeToLive": 0, "comment": { "message": "" }, "replicaSpecifications": [] }