# CREATE TABLE

## CREATE TABLE

## Syntax

```sql
CREATE TABLE table_name (
   column_name data_type [, ...]
   [, PRIMARY KEY (column_name [, ...])]
) WITH (table_parameter = value [, ...]);
```

## Description

This DDL statement is used to define a new [Table](https://docs.deltastream.io/overview/core-concepts/databases#table).

{% hint style="info" %}
**Note** Currently, you can use `CREATE TABLE` only to define a new table backed by a pre-existing Iceberg Table.
{% endhint %}

## Arguments

**`table_name`**

Specifies the name of the table. If the name is case-sensitive, you must wrap it in double quotes; otherwise, the system uses the lower case name.

**`column_name`**

The name of a column in the stream. If the name is case-sensitive, you must wrap it in double quotes; otherwise, the system uses the lower case name.

**`data_type`**

The data type of the column. This can include array specifiers. For more information on the data types supported by DeltaStream, see the [Data Types](https://docs.deltastream.io/reference/sql-syntax/data-types) reference.

**`WITH (table_parameter = value [, …​ ])`**

Optionally, this clause specifies table parameters.

## Table Parameters <a href="#stream_parameters" id="stream_parameters"></a>

| Parameter Name | Description                                                                                                                                                                                                                                                                                                                                                                                                    |
| -------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `store`        | <p>The name of the store that hosts the entity for this stream.<br></p><p><strong>Required:</strong> No<br><strong>Default value:</strong> User’s default <a data-mention href="/pages/khAma1ENd997ICjDGcJW">/pages/khAma1ENd997ICjDGcJW</a>.</p><p><strong>Type:</strong> String<br><strong>Valid values:</strong> See <a data-mention href="/pages/yGCSID06tqSuDcvkGevU">/pages/yGCSID06tqSuDcvkGevU</a></p> |

### **Snowflake-Specific Parameters**

| Parameter Name            | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| ------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `snowflake.db.name`       | <p>The name of the Snowflake database that would host the Snowflake <a data-mention href="/pages/6UJYcUVtorC4Xmf9nEwB#table">/pages/6UJYcUVtorC4Xmf9nEwB#table</a>.<br></p><p><strong>Required:</strong> Yes<br><strong>Default values:</strong> None<br><strong>Type:</strong> String<br><strong>Valid values:</strong> Database names available from <a data-mention href="/pages/ZVNhODGeUbLHKEa7VuaP">/pages/ZVNhODGeUbLHKEa7VuaP</a>.</p>                                                                                                                                                                        |
| `snowflake.schema.name`   | <p>The name of the Snowflake schema that would host the Snowflake <a data-mention href="/pages/6UJYcUVtorC4Xmf9nEwB#table">/pages/6UJYcUVtorC4Xmf9nEwB#table</a>.<br></p><p><strong>Required:</strong> Yes<br><strong>Default value:</strong> None<br><strong>Type:</strong> String<br><strong>Valid values:</strong> Schema names available from <a data-mention href="/pages/ZVNhODGeUbLHKEa7VuaP">/pages/ZVNhODGeUbLHKEa7VuaP</a> under the <code>snowflake.db.name</code> database name.</p>                                                                                                                      |
| `snowflake.table.name`    | <p>The name of the Snowflake table to use when creating the <a data-mention href="/pages/6UJYcUVtorC4Xmf9nEwB#table">/pages/6UJYcUVtorC4Xmf9nEwB#table</a>. If the table doesn't exist in the store, a table with the <code>table\_name</code> is created in the corresponding store.<br><br><strong>Required:</strong> No<br><strong>Default value:</strong> <code>table\_name</code><br><strong>Type:</strong> String</p>                                                                                                                                                                                           |
| `snowflake.buffer.millis` | <p>The amount of time to buffer events with the sink <a data-mention href="/pages/6UJYcUVtorC4Xmf9nEwB#table">/pages/6UJYcUVtorC4Xmf9nEwB#table</a> before writing the data into the corresponding Snowflake table.<br></p><p>It is important to note that the longer events are buffered, the larger the internal state of the query gets. Depending on the volume and size of the events for the corresponding query, memory limitations may be reached.<br><br><strong>Required:</strong> No<br><strong>Default value:</strong> 1000<br><strong>Type:</strong> Long<br><strong>Valid values:</strong> (0, ...]</p> |

Snowflake stores provide a delivery guarantee of `at_least_once` when producing events into a sink [Database](/overview/core-concepts/databases.md#table). Snowflake stores provide an insert-only mode when writing to Snowflake tables.

### **Databricks-Specific Parameters**

| Parameter Name             | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| -------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `databricks.catalog.name`  | <p>The name of the Databricks catalog that would host the Databricks <a data-mention href="/pages/6UJYcUVtorC4Xmf9nEwB#table">/pages/6UJYcUVtorC4Xmf9nEwB#table</a>.<br></p><p><strong>Required:</strong> Yes<br><strong>Default values:</strong> None<br><strong>Type:</strong> String<br><strong>Valid values:</strong> Database names available from <a data-mention href="/pages/ZVNhODGeUbLHKEa7VuaP">/pages/ZVNhODGeUbLHKEa7VuaP</a>.</p>                                                                                                                                                                                                                                                                              |
| `databricks.schema.name`   | <p>The name of the Databricks schema that would host the Databricks <a data-mention href="/pages/6UJYcUVtorC4Xmf9nEwB#table">/pages/6UJYcUVtorC4Xmf9nEwB#table</a>.<br></p><p><strong>Required:</strong> Yes<br><strong>Default value:</strong> None<br><strong>Type:</strong> String<br><strong>Valid values:</strong> Schema names available from <a data-mention href="/pages/ZVNhODGeUbLHKEa7VuaP">/pages/ZVNhODGeUbLHKEa7VuaP</a> under the <code>databricks.catalog.name</code> catalog name.</p>                                                                                                                                                                                                                      |
| `databricks.table.name`    | <p>The name of the Databricks table to use when creating the <a data-mention href="/pages/6UJYcUVtorC4Xmf9nEwB#table">/pages/6UJYcUVtorC4Xmf9nEwB#table</a>. A table with the <code>table\_name</code> is created in the corresponding store. If that table already exists, then an error is reported back to the user.<br><br><strong>Required:</strong> No<br><strong>Default value:</strong> <code>table\_name</code><br><strong>Type:</strong> String</p>                                                                                                                                                                                                                                                                |
| `table.data.file.location` | <p>The S3 directory location for the Delta-formatted data to be written. This location is either a full S3 path, or a relative path to the data store's Cloud Provider Bucket (see <a data-mention href="/pages/7FWIfCeUUJkQEcKKHSRB">/pages/7FWIfCeUUJkQEcKKHSRB</a>). The credentials for writing to S3 are given during data store creation (see <a data-mention href="/pages/7FWIfCeUUJkQEcKKHSRB">/pages/7FWIfCeUUJkQEcKKHSRB</a>). Note that the S3 bucket from the location specified by this parameter must match the <code>databricks.cloud.s3.bucket</code> property defined in the data store.<br><br><strong>Required:</strong> Yes<br><strong>Default value:</strong> None<br><strong>Type:</strong> String</p> |

Databricks stores provide a delivery guarantee of `exactly_once` when producing events into a sink [Database](/overview/core-concepts/databases.md#table). Databricks stores provide an insert-only mode when writing to Databricks tables.

### Postgres-Specific Parameters

| Parameter Name         | Description                                                                                                                                                                                                                   |
| ---------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| postgresql.db.name     | <p><strong>Required</strong>: Yes</p><p><br>See <a href="https://docs.deltastream.io/reference/sql-syntax/query/change-data-capture-cdc#step-1.-ddl-for-cdc-source">CDC source parameters</a> for the same parameter name</p> |
| postgresql.schema.name | <p><strong>Required</strong>: Yes</p><p><br>See <a href="https://docs.deltastream.io/reference/sql-syntax/query/change-data-capture-cdc#step-1.-ddl-for-cdc-source">CDC source parameters</a> for the same parameter name</p> |
| postgresql.table.name  | <p><strong>Required</strong>: No</p><p><br>See <a href="https://docs.deltastream.io/reference/sql-syntax/query/change-data-capture-cdc#step-1.-ddl-for-cdc-source">CDC source parameters</a> for the same parameter name</p>  |

### Iceberg-Specific Parameters

| Parameter Name                | Description                                                                                                                                                                                                                                      |
| ----------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `iceberg.aws.glue.db.name`    | <p>The name of the database (namespace) in the AWS Glue instance (used as the Iceberg Catalog implementation in the Iceberg Store) containing the existing Iceberg table. <strong>Required:</strong> Yes</p><p><strong>Type:</strong> String</p> |
| `iceberg.aws.glue.table.name` | <p>The name of the existing Iceberg table in the AWS Glue instance (used as the Iceberg Catalog implementation in the Iceberg Store).</p><p><strong>Required:</strong> Yes</p><p><strong>Type:</strong> String</p>                               |

## Example

#### Create a new table backed by an Iceberg table

The following creates a new Table, named `pageviews_iceberg`. This table is backed by an existing Iceberg table, called `iceberg_table` in the `iceberg_store` store. `iceberg_table` is defined in the `gluedb` database in the AWS Glue catalog, used by the store.

```sql
CREATE TABLE pageviews_iceberg (
  viewtime BIGINT, 
  userid VARCHAR, 
  pageid VARCHAR) WITH (
  'store'='iceberg_store',
  'iceberg.aws.glue.db.name'='gluedb',
  'iceberg.aws.glue.table.name'='iceberg_table'
);

```

#### Create a new table backed by a PostgreSQL table

The following statement creates a new table named `pg_visits`. This table is backed by an existing PostgreSQL table `public.visits` in the PostgreSQL store configured for the `demo` database. The table defines two columns, `userid` and `cnt`, with `userid` designated as the primary key.

```sql
CREATE TABLE pg_visits (
 userid VARCHAR,
 cnt BIGINT, 
 PRIMARY KEY(userid)) WITH (
  'store'='pg_store',
  'postgresql.db.name'='demo',
  'postgresql.schema.name'='public',
  'postgresql.table.name'='visits'
);
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.deltastream.io/reference/sql-syntax/ddl/create-table.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
