With every month, we get more Snowflake updates! This month, we’ve seen the general release of Stream on Views hit General Availability!
To celebrate this, we’ve created this basic challenge, focussed on Streams.
Use the following block of code to quickly form your table/view basis :
-- Create first table
CREATE TABLE employees (
-- Insert example data into first table
INSERT INTO employees (id, name, department)
(1, "Alice" "Sales"),
(2, "Bob", "Marketing");
-- Create second table
CREATE TABLE sales (
sale_amount DECIMAL(10, 2)
-- Insert example data into second table
INSERT INTO sales (id, employee_id, sale_amount)
(1, 1, 100.00),
(2, 1, 200.00),
(3, 2, 150.00);
-- Create view that combines both tables
CREATE VIEW employee_sales AS
SELECT e.id, e.name, e.department, s.sale_amount
FROM employees e
JOIN sales s ON e.id = s.employee_id;
-- Query the view to verify the data
SELECT * FROM employee_sales;
We’ve had some issues with sales being rung-up but then not showing up in the system anymore. We’ve got a feeling that they’re being removed and would like to very quickly see if that’s the case. Could you help out the store with the following?
Use the above structure to :
– Add a stream to the employee_sales VIEW
– Keep track of every deletion that was made
– Move these into a new table called ‘deleted_sales’
Used as chance to practice stream, will use it with task in the future to move batch of data.
Another nice demo of new functionality, thanks
Thank you, I have added to my toolbox.
Jamie Laird says
Here’s my solution. An automated process for moving records from the stream to deleted_sales table would definitely be the way to go if doing this in the real world, but I kept it simple here. Thanks for another fun task!
This was indeed not very “dbt-friendly” but here’s my attempt anyway