title: Using "UPDATE" and "SET" in Python to Update Snowflake Table
body: <p>I have been using Python to read and write data to Snowflake for some time now to <strong>a table I have full update rights to</strong> using a Snowflake helper class my colleague found on the internet. Please see below for the class I have been using with my personal Snowflake connection information abstracted and a simply read query that works given you have a 'TEST' table in your schema.</p>
  <pre><code>from snowflake.sqlalchemy import URL
  from sqlalchemy import create_engine
  import keyring
  import pandas as pd
  from sqlalchemy import text
  
  # Pull the username and password to be used to connect to snowflake
  stored_username = keyring.get_password('my_username', 'username')
  stored_password = keyring.get_password('my_password', 'password')
  
  class SNOWDBHelper:
  
      def __init__(self):
          self.user = stored_username
          self.password = stored_password
          self.account = 'account'
          self.authenticator = 'authenticator'
          self.role = stored_username + '_DEV_ROLE'
          self.warehouse = 'warehouse'
          self.database = 'database'
          self.schema = 'schema'
  
      def __connect__(self):
          self.url = URL(
              user=stored_username,
              password=stored_password,
              account='account',
              authenticator='authenticator',
              role=stored_username + '_DEV_ROLE',
              warehouse='warehouse',
              database='database',
              schema='schema'
  
          )
          # =============================================================================
          self.url = URL(
              user=self.user,
              password=self.password,
              account=self.account,
              authenticator=self.authenticator,
              role=self.role,
              warehouse=self.warehouse,
              database=self.database,
              schema=self.schema
  
          )
          self.engine = create_engine(self.url)
          self.connection = self.engine.connect()
  
      def __disconnect__(self):
          self.connection.close()
  
      def read(self, sql):
          self.__connect__()
          result = pd.read_sql_query(sql, self.engine)
          self.__disconnect__()
          return result
  
      def write(self, wdf, tablename):
          self.__connect__()
          wdf.to_sql(tablename.lower(), con=self.engine, if_exists='append', index=False)
          self.__disconnect__()
  
  # Initiate the SnowDBHelper()
  SNOWDB = SNOWDBHelper()
  
  query = &quot;&quot;&quot;SELECT * FROM &quot;&quot;&quot; + 'TEST'
  snow_table = SNOWDB.read(query)
  
  </code></pre>
  <p>I now have the need to update an existing Snowflake table and my colleague suggested I could use the read function to send the query containing the update SQL to my Snowflake table. So I adapted an update query I use successfully in the Snowflake UI to update tables and used the read function to send it to Snowflake. <strong>It actually tells me that the relevant rows in the table have been updated, but they have not.</strong> Please see below for update query I use to attempt to change a field &quot;field&quot; in &quot;test&quot; table to &quot;X&quot; and the success message I get back. Not thrilled with this hacky update attempt method overall (where the table update is a side effect of sorts??), but could someone please help with method to update within this framework?</p>
  <pre><code># Query I actually store in file: '0-Query-Update-Effective-Dating.sql'
  UPDATE &quot;Database&quot;.&quot;Schema&quot;.&quot;Test&quot; AS UP
  SET UP.FIELD = 'X'
  
  # Read the query in from file and utilize it
  update_test = open('0-Query-Update-Effective-Dating.sql')
  update_query = text(update_test.read())
  SNOWDB.read(update_query)
  
  # Returns message of updated rows, but no rows updated
     number of rows updated  number of multi-joined rows updated
  0                     316                                    0
  </code></pre>