title: PostgreSQL Trigger error
body: <p>I have:</p>
  
  <pre><code>CREATE OR REPLACE FUNCTION aktualizujIloscPodan() RETURNS TRIGGER AS
  $BODY$ 
    DECLARE 
      n integer;
      sid integer;
  BEGIN
  
  sid=0;
  IF (TG_OP='INSERT') THEN
  sid = NEW."studentID";
  ELSIF (TG_OP='DELETE') THEN
  sid = OLD."studentID";
  END IF;
  
  n = COALESCE ((SELECT count("studentID") as c
  FROM "Podania" WHERE "studentID"=sid
  GROUP BY "studentID"), 0);
  
  UPDATE "Studenci" SET "licznikpodan" = n WHERE "ID"=sid;
  END;
  $BODY$ 
  LANGUAGE plpgsql;
  
  DROP TRIGGER IF EXISTS triggenPodan ON "Podania";
  
  CREATE TRIGGER triggenPodan AFTER INSERT OR DELETE
  ON "Podania"
  EXECUTE PROCEDURE aktualizujIloscPodan();
  </code></pre>
  
  <p>When I try to execute:</p>
  
  <pre><code>DELETE FROM "Podania"
  
  I get
  
  ERROR:  record "old" is not assigned yet
  DETAIL:  The tuple structure of a not-yet-assigned record is indeterminate.
  CONTEXT:  PL/pgSQL function "aktualizujiloscpodan" line 11 at assignment
  
  ********** Błąd **********
  
  ERROR: record "old" is not assigned yet
  Stan SQL:55000
  Szczegóły:The tuple structure of a not-yet-assigned record is indeterminate.
  Kontekst:PL/pgSQL function "aktualizujiloscpodan" line 11 at assignment
  </code></pre>
  
  <p>It seems like it doesn't know what is <code>OLD</code> or <code>NEW</code>. How can I fix that?</p>