title: Postgresql: Loop through each table and check for column?
body: <p>I am trying to write a simple <code>SQL</code> query in <code>pgAdmin</code> to LOOP through each table in a database and change a specified column name IF it exists. I have never coded in <code>SQL</code> but after searching through many forums have managed to come up with:</p>
  
  <pre><code>DO
  BEGIN
  FOR i IN SELECT table_name FROM information_schema.tables
  LOOP
     IF SELECT column_name FROM information_schema.columns WHERE table_name = 'i.table_name'
   THEN
     ALTER TABLE i.table_name RENAME COLUMN old_column_name TO new_column_name
  END IF;
  END LOOP;
  </code></pre>