Update Snowflake table based on data_editor inputs

I created a simple Streamlit app with just an editable table for business users to perform the following:

  1. Edit an existing row
  2. Add a new row
  3. Delete a row

Streamlit pulls the data from a Snowflake table. My goal is to 1) have business users amend the table using the Streamlit app and 2) the edits would then reflect in the Snowflake table.

I need some guidance on the 2).

I couldn’t find a simple example to guide me through the part where an amended table reflects in a Snowflake table.

I found a Data_editor write changed data back to DB, the same as my use case. No luck there.

Is there a simple example I can follow or concepts I should look into?

This is what I have so far.

#connect snowflake to python 
ctx = snowflake.connector.connect(
    user='0000000',
    account='company-name',
    authenticator='externalbrowser',
    )
ctx.cursor().execute('USE warehouse XXX_XX')
ctx.cursor().execute('USE ZZ_ZZZ')

cur = ctx.cursor().execute(query)
df = pd.DataFrame.from_records(iter(cur), columns=[x[0] for x in cur.description])

st.set_page_config(layout='wide', page_title='Portfolio')

with st.form("my_form"):
    edited_df = st.data_editor(df)
    submitted = st.form_submit_button("Submit")

1 Like

You don’t know how to make changes to a snowflake table? Or you don’t know what changes to make?

2 Likes