title: postgresql trigger function add if statement that compares old column value with a default value on update
body: <p>I want to create a trigger function in sql that would prevent update on a column in a table if the column value was not equal to &quot;default_id&quot;. For example, if I update a row where <code>some_id</code> equals to &quot;default_id&quot;, it would succeed. However, if I update a row <code>some_id</code> column that has a value that isn't equal to &quot;default_id&quot;, it would throw an exception.</p>
  <pre><code>CREATE FUNCTION not_allow_update_column_some_id() RETURNS trigger
      LANGUAGE plpgsql AS
  $$BEGIN
      IF NEW.some_id &lt;&gt; OLD.some_id AND OLD.some_id &lt;&gt; &quot;default_id&quot; THEN
          RAISE EXCEPTION 'some_id is not allowed to be updated unless it was equal to default value';
      END IF;
      RETURN NEW;
  END;$$;
  
  CREATE TRIGGER not_allow_update_column_some_id
      BEFORE UPDATE ON some_table FOR EACH ROW
  EXECUTE PROCEDURE not_allow_update_column_some_id();
  </code></pre>
  <p>The above code doesn't seem to work as the compare seems to think &quot;default_id&quot; is a column instead of a value.</p>