Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

document dynamic tables #41

Merged
merged 1 commit into from
Aug 6, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions content/en/user-guide/dynamic-tables/index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
---
title: "Dynamic Tables"
linkTitle: "Dynamic Tables"
weight: 13
description: Get started with Dynamic Tables in LocalStack for Snowflake
---

## Introduction

Snowflake Dynamic Tables enable a background process to continuously load new data from sources into the table, supporting both delta and full load operations. A dynamic table automatically updates to reflect query results, removing the need for a separate target table and custom code for data transformation. This table is kept current through regularly scheduled refreshes by an automated process.

The Snowflake emulator supports Dynamic tables, allowing you to create and manage Dynamic tables locally. The following operations are supported:

* [`CREATE DYNAMIC TABLE`](https://docs.snowflake.com/en/sql-reference/sql/create-dynamic-table)
* [`DROP DYNAMIC TABLE`](https://docs.snowflake.com/en/sql-reference/sql/drop-dynamic-table)

## Getting started

This guide is designed for users new to Dynamic tables and assumes basic knowledge of SQL and Snowflake. Start your Snowflake emulator and connect to it using an SQL client in order to execute the queries further below.

In this guide, you will create a table, create a dynamic table, insert data into the table, and query the dynamic table.

### Create a table

You can create a table using the `CREATE TABLE` statement. Run the following query to create a table:

```sql
CREATE TABLE example_table_name (id int, name text);
```

The output should be:

```sql
+-----------------------------------------------+
| status |
| ----------------------------------------------+
| Table EXAMPLE_TABLE_NAME successfully created.|
+-----------------------------------------------+
```

### Create a dynamic table

You can create a dynamic table using the `CREATE DYNAMIC TABLE` statement. Run the following query to create a dynamic table:

```sql
CREATE OR REPLACE DYNAMIC TABLE t_12345
TARGET_LAG = '1 minute' WAREHOUSE = 'test' REFRESH_MODE = auto INITIALIZE = on_create
AS SELECT id, name FROM example_table_name;
```

The output should be:

```sql
+-----------------------------------------------+
| result |
| ----------------------------------------------+
Dynamic table T_12345 successfully created. |
+-----------------------------------------------+
```

### Insert data into the table

You can insert data into the table using the `INSERT INTO` statement. Run the following query to insert data into the table:

```sql
INSERT INTO example_table_name(id, name) VALUES (1, 'foo'), (2, 'bar');
```

The output should be:

```sql
| count |
| -----+ |
| 2 |
```

### Query the dynamic table

You can query the dynamic table using the `SELECT` statement. Run the following query to query the dynamic table:

```sql
SELECT * FROM t_12345;
```

The output should be:

```sql
+----+------+
| ID | NAME |
| ---+------+
| 1 | foo |
| 2 | bar |
+----+------+
```
Loading