Not every new feature had a big announcement at Summit 2023, but that doesn’t mean we can’t spotlight it!
This week we’ve got a puzzle for you to crack and without spoiling everything, let’s see if you can figure out the puzzle from the starting code :
Startup Code
-- database and schema creation
CREATE DATABASE F_F_WEEK_54;
CREATE SCHEMA WEEK_54;
--table creation
CREATE TABLE table_a (
id INT,
name VARCHAR,
age INT
);
CREATE TABLE table_b (
id INT,
name VARCHAR,
age INT
);
--data creation
INSERT INTO table_a (id, name, age)
VALUES
(1, 'John', 25),
(2, 'Mary', 30),
(3, 'David', 28),
(4, 'Sarah', 35),
(5, 'Michael', 32),
(6, 'Emily', 27),
(7, 'Daniel', 29),
(8, 'Olivia', 31),
(9, 'Matthew', 26),
(10, 'Sophia', 33),
(11, 'Jacob', 24),
(12, 'Emma', 29),
(13, 'Joshua', 32),
(14, 'Ava', 30),
(15, 'Andrew', 28),
(16, 'Isabella', 34),
(17, 'James', 27),
(18, 'Mia', 31),
(19, 'Logan', 25),
(20, 'Charlotte', 29);
--role creation
CREATE ROLE week_54_role;
GRANT ROLE week_54_role to user <user_name> ;
GRANT USAGE ON database F_F_WEEK_54 TO ROLE week_54_role;
GRANT USAGE ON schema WEEK_54 TO ROLE week_54_role;
GRANT SELECT ON ALL TABLES IN SCHEMA F_F_WEEK_54.WEEK_54 TO ROLE week_54_role;
GRANT INSERT ON ALL TABLES IN SCHEMA F_F_WEEK_54.WEEK_54 TO ROLE week_54_role;
GRANT USAGE ON WAREHOUSE TO ROLE week_54_role;
As you can see, we create 2 simple tables and a new role that can select and insert from these tables. We now wish to use that role to create and execute a stored procedure to move data from table A to table B. HOWEVER, the role that we’ve created doesn’t have the CREATE PROCEDURE privilege!
The challenge for today is to create and execute the following procedure without granting the CREATE PROCEDURE privilege:
Procedure
CREATE OR REPLACE copy_to_table(fromTable STRING, toTable STRING, count INT) RETURNS STRING LANGUAGE PYTHON RUNTIME_VERSION = '3.8' PACKAGES = ('snowflake-snowpark-python') HANDLER = 'copyBetweenTables' AS $$ def copyBetweenTables(snowpark_session, fromTable, toTable, count): snowpark_session.table(fromTable).limit(count).write.mode("append").save_as_table(toTable) return "Success" $$ ;
You solution should keep the procedure intact, and this piece of code needs to be part of your solution:
CALL copy_to_table('table_a', 'table_b', 5);
One response to “Week 54 – Intermediate”
-
Another fun challenge, thank you. To keep up the mystery, I strongly hope nobody looks at each other’s solutions until they’ve figured it out themselves!
- Solution URL – https://github.com/ChrisHastieIW/Frosty-Friday
Leave a Reply
You must be logged in to post a comment.