Introduction to Snowflake SQL
Palak Raina
Senior Data Engineer
Snowflake
SHOW
DESCRIBE
INSERT
UPDATE
MERGE
COPY
Similarities to Postgres
INSERT
UPDATE
MERGE
Snowflake
SHOW
SHOW DATABASES
SHOW TABLES IN { DATABASE [ <db_name> ] }
SHOW TABLES IN DATABASE PIZZA_SALES
SHOW TABLES [ LIKE '<pattern>' ]
[ IN { DATABASE [ <db_name> ] } ]
SHOW TABLES LIKE '%PIZZA%' IN DATABASE PIZZA_SALES
SHOW SCHEMAS IN DATABASE PIZZA_SALES
SHOW COLUMNS IN PIZZA_TYPE
SHOW VIEWS IN DATABASE PIZZA_SALES
DESCRIBE
or DESC
DESCRIBE DATABASE PIZZA_SALES
DESCRIBE SCHEMA PUBLIC
DESCRIBE TABLE PIZZA_TYPE
DESCRIBE VIEW ORDERS_VIEW
DESCRIBE STAGE my_local_stage
INSERT INTO orders (order_id, order_date, order_time)
VALUES (1, '2015-01-01', '11:38:36')
INSERT INTO orders_filtered
SELECT * FROM orders
WHERE order_date > '2015-01-02'
UPDATE orders
SET order_time = '17:00:00'
WHERE order_id = '5'
Before:
After:
MERGE INTO orders_filtered AS target -- Target table USING orders AS source -- Source table
ON target.order_id = source.order_id -- Common column
WHEN MATCHED THEN -- When there is a match UPDATE SET -- Update order_date and time of target table target.order_date = source.order_date, target.time = source.order_time
Source table: orders
Before Merge: orders_filtered
After Merge: orders_filtered
updated order_id = 5
based on orders
table
Snowflake:
COPY INTO orders FROM @my_local_stage/orders.csv
FILE_FORMAT = (TYPE = 'CSV' SKIP_HEADER=1 )
@my_local_stage
: stage we have created.orders.csv
: file within that stage we're copying data from.FILE_FORMAT
: format of the source data, in this case, a CSV.Introduction to Snowflake SQL