title: How to specify a trigger function to execute only when there are records in a table?
body: <p>I am using postgres 10.9. I created a trigger function and trigger on a table after insert. Now when I insert a record, it gives me error because initially there is no data in the table </p>
  
  <p>Error: control reached end of trigger procedure without RETURN</p>
  
  <p>How can I make sure that the function executes only when there are records in the table?</p>
  
  <p>Trigger function-</p>
  
  <pre><code>create or replace function delete_old_token()
  returns trigger as
  $body$
  begin
  delete from token where timestamp &lt; NOW() - interval '1 day';
  end;
  $body$
  language plpgsql;
  </code></pre>
  
  <p>Trigger-</p>
  
  <pre><code>create trigger delete_token
  after insert
  on token
  for each row
  execute procedure delete_old_token();
  </code></pre>
  
  <p>Is there a way to achieve this?</p>