Reading data from Snowflake into Google Sheets

Introduction

Prerequisites

USE ROLE USERADMIN;CREATE OR REPLACE ROLE NFLX_GS;CREATE OR REPLACE USER GSHEETS_USR PASSWORD='******' DEFAULT_ROLE='NFLX_GS' MUST_CHANGE_PASSWORD = FALSE;USE ROLE SYSADMIN;
GRANT USAGE ON WAREHOUSE PUBLIC_WH TO ROLE NFLX_GS;
GRANT USAGE ON DATABASE NFLX_DB TO ROLE NFLX_GS;
GRANT USAGE ON SCHEMA NFLX_DB.PUBLIC TO ROLE NFLX_GS;
GRANT SELECT ON TABLE NFLX_DB.PUBLIC.NFLX TO ROLE NFLX_GS;
GRANT ROLE NFLX_GS TO USER GSHEETS_USR;
-- test if role has access to NFLX table
USE ROLE NFLX_GS;
USE WAREHOUSE PUBLIC_WH;
SELECT * FROM NFLX_DB.PUBLIC.NFLX LIMIT 10;

Authentication

openssl genrsa 2048 | openssl pkcs8 -topk8 -inform PEM -out private_key.p8 -nocryptopenssl rsa -in private_key.p8 -outform PEM -pubout -out public.pem
USE ROLE USERADMIN;
ALTER USER GSHEETS_USR SET RSA_PUBLIC_KEY='MIIB......';

Google Sheets

  • My demo account name is ‘sfseeurope-eu-demo58’, it is used in lines 23, 47 and 48. Replace the account name with your account name.
  • This account resides in region ‘eu-central-1’. Replace this if your account is in another region (line 23)
  • The SHA256 public key fingerprint in line 48, see below for instructions
  • The private key in line 57. Further instructions below

Public Key fingerprint

openssl pkey -pubin -in public.pem -outform der | openssl dgst -sha256 -binary | openssl enc -base64
USE ROLE USERADMIN;
DESC USER GSHEETS_USR;

Private Key

awk 'NF {sub(/\r/, ""); printf "%s\\n",$0;} END {printf "\n\n"}' private_key.p8

Conclusion

Closing remarks

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store