Trigger error [plpgsql]
<p>Ok so i have these tables. Answer and Question.</p>

<p><strong>Answer table</strong> has:</p>

<p>answerID (PK)</p>

<p>answer</p>

<p>datePosted</p>

<p>questionID</p>

<p>email</p>

<p><strong>Question table</strong> has:</p>

<p>questionID (PK)</p>

<p>question</p>

<p>datePosted</p>

<p>email</p>

<p>i want to make sure that the user(email) that answers a question belongs to the user network of the user(email) that did a question. My user network can be created through another table that has no business here. I have a function that finds the user network of a specific user. So i wrote the following code:</p>

<pre><code>CREATE OR REPLACE FUNCTION "Social_Network".answers_only_by_users_in_user_network()
  RETURNS TRIGGER AS

  $$
  begin
   IF new.email NOT IN (select network_email from     "Social_Network".find_user_network(question.email)) then
      RAISE EXCEPTION 'user that answered does not belong in user network';
      return null;
   else
      return new;
   end if;
  end;
  $$
  LANGUAGE plpgsql VOLATILE


  CREATE TRIGGER answer_restriction BEFORE INSERT OR UPDATE ON     "Social_Network".answer
   for each row execute procedure     "Social_Network".answers_only_by_users_in_user_network();
</code></pre>

<p>the function find_user_network finds the user network of a specific user.
i am making this trigger for the Answer table but i have a problem in the IF statement because in the input argument of the function find_user_network i want to put the email from the table Question. But it pops error when i am trying to edit the data from the above tables to check if my trigger works properly.
The error says that i am missing the FROM clause-entry for table Question and it points my line 3 of the trigger function where the if statement is.</p>

<p>My trigger has been created successfully and my trigger function as well. But that error persists. Any ideas on what i am doing wrong?
Thanks!</p>