Created
June 8, 2019 06:53
-
-
Save hsuyuming/c410f266f3ef496f1cc979c571af3d9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import snowflake connector module | |
import snowflake.connector | |
import sys | |
import os | |
# 確定輸入的參數是否給定正確 | |
# Sample: python connect_v1.py <account> <region> <user> <role> <warehouse> <database> <schema> | |
if len(sys.argv) < 8 : | |
print("ERROR: Please pass the following command-line parameters in order:",end='\n') | |
print("account,region,user,role,warehouse,database,schema.") | |
sys.exit(-1) | |
else: | |
ACCOUNT = sys.argv[1] | |
REGION = sys.argv[2] | |
USER = sys.argv[3] | |
ROLE = sys.argv[4] | |
WAREHOUSE = sys.argv[5] | |
DATABASE = sys.argv[6] | |
SCHEMA = sys.argv[7] | |
# 從環境變數中取得密碼 | |
PASSWORD = os.getenv("SNOWSQL_PWD") | |
if PASSWORD == None or PASSWORD == '': | |
print("ERROR: Please set SNOWSQL_PWD env variable to your password") | |
sys.exit(-2) | |
con = snowflake.connector.connect( | |
account=ACCOUNT, | |
region=REGION, | |
user=USER, | |
role=ROLE, | |
password= PASSWORD, | |
warehouse=WAREHOUSE, | |
database=DATABASE, | |
schema=SCHEMA | |
) | |
results = con.cursor().execute("SELECT * FROM LIBRARY LIMIT 1") | |
for result in results: | |
print(result[0]) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment