In snowflake, an _ is created to reference the folder directory on cloud (like S3 bucket).
external stage
A table can be created pointing to the stage, that allows Snowflake to query data from cloud directory (mapped to the stage).
How to provide Snowflake permission to access cloud directory?
Assume required role with permission policy is already created in cloud (AWS).
CREATE STORAGE INTEGRATION my_s3_integration
TYPE = EXTERNAL_STAGE
STORAGE_PROVIDER = S3
ENABLED = TRUE
STORAGE_AWS_ROLE_ARN = 'arn:aws:iam::<your-account-id>:role/<your-role-name>'
STORAGE_ALLOWED_LOCATIONS = ('s3://your-bucket/path/');STORAGE_AWS_IAM_USER_ARN and STORAGE_AWS_EXTERNAL_IDDESC INTEGRATION my_s3_integration;
{
"Version": "2012-10-17",
"Statement": [
{
"Effect": "Allow",
"Principal": {
"AWS": "arn:aws:iam::<snowflake-account-id>:user/<snowflake-user>"
},
"Action": "sts:AssumeRole",
"Condition": {
"StringEquals": {
"sts:ExternalId": "<external-id-from-desc>"
}
}
}
]
}AWS_EXTERNAL_ID property from external stage
create an external STAGE in Snowflake using STORAGE INTEGRATION.
CREATE OR REPLACE STAGE my_s3_stage URL = 's3://your-bucket/path/' STORAGE_INTEGRATION = my_s3_integration FILE_FORMAT = (TYPE = CSV);
Create an external table from external stage in Snowflake
CREATE OR REPLACE EXTERNAL TABLE my_ext_table ( col1 STRING, col2 STRING ) WITH LOCATION = @my_s3_stage FILE_FORMAT = (TYPE = CSV);
Provide correct order of steps for loading data into Snowflake from a cloud provider.
* a) Create the stage.
* b) Refresh the stage.
* c) Create storage integration.
* d) Load data into table from stage
* e) Reference the stage in table creation
Two benefits of using Storage Integration:
_ role has complete access to Snowflake account.
ACCOUNTADMIN
manages account-level tasks like billing.
_ role has privileges to create warehouses and databases (and other objects) in an account.
SYSADMIN
_ role is dedicated to user and role management
USERADMIN
Can create users and roles in the account
How to assign a user the privilege to manage objects owned by the CUSTOM_ADMIN_HR role?
While creating the user, set the ‘Default Role’ field to CUSTOM_ADMIN_HR from the dropdown.
You created a new warehouse that you want users with SYSADMIN role to be allowed to use. How will you achieve it?
Convert ‘80’ into number in Snowflake SQL.
cast('80' as int)Convert order_timestamp
(2015-01-01 11:38:36.000 -0800) to date.
cast(order_timestamp as date)
Capitalize each word of string in Snowflake SQL
INITCAP()