title: PostgreSQL 10 error relation new doesn't exist on before update trigger
body: <p>My before update trigger throws an error on updating single row in table company.</p>
  
  <pre><code>ERROR:  relation "new" does not exist, row 7.
  </code></pre>
  
  <p>Trigger and trigger function code:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION public.check_company_transitivity()
      RETURNS trigger
      AS $$
  DECLARE
      cmp uuid;
      head_company uuid;
      audited_company uuid;
  BEGIN
      audited_company := (select NEW.id from NEW);
      cmp:=audited_company;
      head_company:='*';
      while head_company is not null loop
          head_company:=(select head_company from company where id=cmp);
          if audited_company=head_company then
              raise exception 'transitive closure';
          else
              cmp=head_company;
          end if;
      end loop;
  return new;
  END;
  $$  LANGUAGE plpgsql;
  
  
  create trigger check_company_transitivity 
  before update
  on
  public.company for each row execute procedure check_company_transitivity();
  </code></pre>
  
  <p>I can’t understand what the problem is, I would be appreciate for any help.</p>