What the components of a dynamic table definition, including the SQL statement and refresh schedule?

75 viewsDynamic Tables

Can you describe the components of a dynamic table definition, including the SQL statement and refresh schedule?

Daniel Steinhold Asked question March 15, 2024

A dynamic table definition in Snowflake consists of two main components:

  1. SQL Statement: This is the heart of a dynamic table, defining the logic for transforming and filtering the source data. It's written in standard SQL and can include joins, aggregations, filtering clauses, and other transformations. This query essentially defines the structure and content of the resulting dynamic table.

  2. Refresh Schedule: This determines how often Snowflake refreshes the dynamic table to reflect changes in the underlying data sources. You can specify various options for scheduling, including:

    • Continuous: The table updates continuously as changes occur in the source data (useful for real-time scenarios).
    • Scheduled: You define a specific schedule for automatic refreshes (e.g., hourly, daily).
    • Manual: You trigger the refresh manually whenever needed.

Optional Components:

  • Retention Period: You can define a time frame for how long Snowflake keeps historical versions of the dynamic table data.
  • Clustering Key: This helps Snowflake optimize query performance by clustering data based on frequently used columns.

Here's an example of a dynamic table definition with all the components:

REFRESH => ON DEMAND  -- Manual refresh
  SUM(order_amount) AS total_sales,
  AVG(discount_rate) AS average_discount
FROM orders
GROUP BY customer_id;

In this example:

  • The SQL statement calculates total sales and average discount per customer.
  • The refresh schedule is set to manual, meaning you'll need to trigger the refresh yourself.

Overall, a dynamic table definition provides a concise and declarative way to define how you want your transformed data to look, along with how often it should be updated.

Daniel Steinhold Changed status to publish March 15, 2024
You are viewing 1 out of 1 answers, click here to view all answers.
Feedback on Q&A