Reputation: 289
I am building a StreamLit appication in Snowflake. I am using a grid editor initially loading data from a table. Users can change the data in certain columns. When the users hit a submit button I want to merge the data in the table in the below merge command (dataset.merge(updated_dataset ...). I was able to update a single column = Column1 (below code works for that). But I would like to update also Column2, Column3 columns (both source and target dataframes have the same structure, column names etc). What is the syntax I would need to use to be able to update 3 (Column1, Column2, Column3) columns in the below code line.
dataset.merge(updated_dataset, (dataset["Id"] == updated_dataset["Id"]), [when_matched().update({"Column1": updated_dataset["Column1"]})])
Below is more of the same code block
import streamlit as st
from snowflake.snowpark.context import get_active_session
import datetime
from datetime import timedelta, date
import dateutil
from dateutil.relativedelta import relativedelta
import time
import pandas as pd
from snowflake.snowpark.functions import when_matched
...
dataset = session.table("TEMP_TEST_TABLE")
...
updated_dataset=session.create_dataframe(edited)
...
#Below works for updating single column, I am not able to figure out how to be able to update Column1, Column2, Column3 from the both identical dataframes
dataset.merge(updated_dataset, (dataset["Id"] == updated_dataset["Id"]), [when_matched().update({"Column1": updated_dataset["Column1"]})])
Upvotes: 0
Views: 25
Reputation: 3
Have you tried using comma separated column below
dataset.merge(updated_dataset, (dataset["Id"] == updated_dataset["Id"]), [when_matched().update({"Column1": updated_dataset["Column1"],"Column2": updated_dataset["Column2"],"Column3": updated_dataset["Column3"]})])
Upvotes: 0