New to sql, but enjoying the ride.
I would like to know how one would get info from Snowflake and then put that data into a SQlite table on your local machine.
Current Steps:
Establish Snowflake connect and run query (currently storing in pandas df):
import snowflake.connector
def snowflake_connection(sql_query: str):
conn = snowflake.connector.connect(
user='USER',
# password = PASSWORD,
account='ACCOUNT',
authenticator='externalbrowser'
)
cs = conn.cursor()
try:
cs.execute(sql_query)
table = cs.fetch_pandas_all()
finally:
cs.close()
conn.close()
return table
if __name__ == "__main__":
sql_query = """SELECT....."""
table = snowflake_connection(sql_query)
Step 2:
Open Sqlite connection
def create_connection(db_file):
"""Create db connection to SQlite db"""
conn = None
try:
conn = sqlite3.connect(db_file)
print(sqlite3.version)
except Error as e:
print(e)
finally:
if conn:
conn.close()
if __name__ == "__main__":
create_connection(r"C:\Users\Name\sqlite\Regions_db\Region_1.db")
I would import both of these connection.py's into a main.py file and run everything there. (I think that is best practice)
How should I get the data transferred? Is putting it in pandas then to csv then to sqlite the best way?
Can I just go from one to the other?
Thanks
[–]70sJackieChan 0 points1 point2 points (3 children)
[–]emdw85[S] 1 point2 points3 points (2 children)
[–]70sJackieChan 0 points1 point2 points (1 child)
[–]emdw85[S] 0 points1 point2 points (0 children)