title: Is it possible to dynamically loop through a table's columns?
body: <p>I have a trigger function for a table test which has the following code snippet:</p>
  
  <pre><code>IF TG_OP='UPDATE' THEN
      IF OLD.locked &gt; 0 AND
   (       OLD.org_id &lt;&gt; NEW.org_id OR
              OLD.document_code &lt;&gt; NEW.document_code OR
              -- other columns ...
   )
  THEN
      RAISE EXCEPTION 'Message';
  -- more code
  </code></pre>
  
  <p>So I am statically checking all the column's new value with its previous value to ensure integrity. Now every time my business logic changes and I have to add new columns into that table, I will have to modify this trigger each time. I thought it would be better if somehow I could dynamically check all the columns of that table, without explicitly typing their name.</p>
  
  <p>How can it be done?</p>