CREATE OR REPLACE FUNCTION clear_topn2_proc()
 RETURNS VOID
 LANGUAGE plpgsql
 VOLATILE
 AS
 $$
 BEGIN
 
 
   DELETE FROM vpx_topn_past_week
    WHERE NOT EXISTS(SELECT 'x'
                       FROM VPX_SAMPLE_TIME2 t
                      WHERE t.sample_time = vpx_topn_past_week.sample_time
                      );
 
 END
 $$