title: Postgres/GIS: RULE does not affect all inserts
body: <p>I have a rule for a table which simply checks if the new entry matches a name and intersects with that matching existing row using <code>st_intersects</code> from postgis library.</p>
  
  <p>It seems that only a part are NOT inserted, but most get through this rule. I checked some entries manually after the insert and can confirm the rule should have blocked that insert.</p>
  
  <p>Is something wrong with my RULE?</p>
  
  <p>Table has 3 columns. <code>id serial</code>, <code>name varchar(200)</code> and <code>way geometry(Linestring,4326)</code></p>
  
  <p>And my RULE is as follows (excerpt from \d names)</p>
  
  <pre><code>blockduplicate AS
      ON INSERT TO nameslist
     WHERE (EXISTS ( SELECT 1
             FROM nameslist
            WHERE nameslist.name::text = new.name::text AND st_intersects(nameslist.way, new.way) = true)) DO INSTEAD NOTHING
  </code></pre>
  
  <p>This table simply takes a line having a name, and whenever another entry comes in with the same name and intersecting with another existing entry having the same name, it should be blocked. So I have only one entry with this name in the area represented by the geometry field way. After the insert I see plenty of duplicates (name matches and <code>st_intersects</code> returns <code>true</code> when checking <code>way</code> field). Why is my rule not blocking the insert? </p>
  
  <p><strong>Update:</strong> Is it because I do multiple inserts in one query. I actually insert 12000 entries in one shot with the query <code>INSERT INTO (a,b,c) VALUES (...),(...),(...),...</code>
  Does PostgreSQL call the RULE for each value? I need to do multiple inserts otherwise it would take months to finish my inserts.</p>