CREATE TABLE command in Amazon QLDB
Important
End of support notice: Existing customers will be able to use Amazon QLDB until end of support on 07/31/2025. For more details, see
Migrate an Amazon QLDB Ledger to Amazon Aurora PostgreSQL
In Amazon QLDB, use the CREATE TABLE
command to create a new
table.
Tables have simple names with no namespaces. QLDB supports open content and doesn't enforce schema, so you don't define attributes or data types when creating tables.
Note
To learn how to control access to run this PartiQL command in a ledger, see Getting started with the standard permissions mode in Amazon QLDB.
Topics
Syntax
CREATE TABLE
table_name
[ WITH (aws_tags = `{'key
': 'value
'}`) ]
Parameters
table_name
-
The unique name of the table to create. An active table with the same name must not already exist. The following are the naming constraints:
-
Must only contain 1–128 alphanumeric characters or underscores.
-
Must have a letter or an underscore for the first character.
-
Can have any combination of alphanumeric characters and underscores for the remaining characters.
-
Is case sensitive.
-
Must not be a QLDB PartiQL reserved word.
-
- '
key
': 'value
' -
(Optional) The tags to attach to the table resource during creation. Each tag is defined as a key-value pair, where the key and value are each denoted by single quotation marks. Each key-value pair is defined inside an Amazon Ion structure that is denoted by backticks.
Tagging tables on creation is currently supported for ledgers in the
STANDARD
permissions mode only.
Return value
tableId
– The unique ID of the table that you
created.
Tagging tables on creation
Note
Tagging tables on creation is currently supported for ledgers in the
STANDARD
permissions mode only.
Optionally, you can tag your table resources by specifying tags in a
CREATE TABLE
statement. For more information about tags, see
Tagging Amazon QLDB resources. The following example
creates a table named Vehicle
with the tag
environment=production
.
CREATE TABLE Vehicle WITH (aws_tags = `{'environment': 'production'}`)
Tagging tables on creation requires access to both the
qldb:PartiQLCreateTable
and qldb:TagResource
actions. To learn more about permissions for QLDB resources, see How Amazon QLDB works with IAM.
By tagging resources while they're being created, you can eliminate the need to run custom tagging scripts after resource creation. After a table is tagged, you can control access to the table based on those tags. For example, you can grant full access only to tables that have a specific tag. For a JSON policy example, see Full access to all actions based on table tags.
Examples
CREATE TABLE VehicleRegistration
CREATE TABLE Vehicle WITH (aws_tags = `{'environment': 'development'}`)
CREATE TABLE Vehicle WITH (aws_tags = `{'key1': 'value1', 'key2': 'value2'}`)
Running programmatically using the driver
To learn how to programmatically run this statement using the QLDB driver, see the following tutorials in Getting started with the driver:
-
Node.js: Quick start tutorial | Cookbook reference
-
Python: Quick start tutorial | Cookbook reference