title: PostgreSQL: How to iterate over a list of table and perform updates
body: <p>I am learning PostgreSQL and I have stumbled over a very basic requirement. 
  I want to iterate over an array of table and update a specific column (the column name is same in all these tables). My idea is to hold these table names in an array and use a for loop to iterate over each table and update the column.</p>
  
  <p>This is what I have done so far:</p>
  
  <pre><code>DO
  $do$
  DECLARE
    old_value varchar := 'old_value';
    new_value varchar := 'new_value';
  
    affected_table_names  TEXT[] := '{"table_1", "table_2"}';
  
  BEGIN
    FOREACH tableName IN affected_table_names
      LOOP
  
        update tableName
        set column_name = old_value
        where column_name = new_value;
  
    END LOOP;
  END
  $do$;
  </code></pre>
  
  <p>However, when I execute this pgAdmin4, I get the following error:</p>
  
  <pre><code>ERROR:  syntax error at or near "affected_table_names"
  LINE 25:   FOR tableName IN affected_table_names
                                  ^
  ********** Error **********
  
  ERROR: syntax error at or near "affected_table_names"
  SQL state: 42601
  Character: 836
  </code></pre>
  
  <p>I am not sure what needs to be done to fix the error. I know it's syntax error, because it says so in here: <a href="https://www.postgresql.org/docs/8.1/errcodes-appendix.html" rel="nofollow noreferrer">https://www.postgresql.org/docs/8.1/errcodes-appendix.html</a></p>
  
  <p>Could anybody please point me in the right direction ? </p>