What to use instead of "INSERT ... ON CONFLICT DO NOTHING" on postgres
<p>I have the following query, which I use with postgres 9.5: </p>

<pre><code>INSERT INTO knowledge_state 
(SELECT learnerid learner_id, lo_id FROM qb_lo_tag WHERE qb_id = NEW.qb_id)
ON CONFLICT DO NOTHING ;
</code></pre>

<p>Unfortunately I can't use postgres 9.5 on some servers, and I need to convert it to a pre - 9.5 friendly query.
I have built the following query instead, but it seems much more complicated to me, and I thought something simpler might be possible..</p>

<pre><code>FOR rows IN SELECT lo_id FROM knowledge_state 
WHERE learner_id = learnerid 
AND lo_id IN (SELECT lo_id FROM qb_lo_tags WHERE qb_id = New.qb_id) LOOP

  INSERT INTO knowledge_state (lo_id, learner_id) SELECT rows.lo_id, learnerid 
WHERE NOT EXISTS (SELECT * FROM knowledge_state WHERE lo_id = rows.lo_id AND learner_id = learnerid);

END LOOP;
</code></pre>

<p>I would love to hear ideas on how to simplify this query.</p>