title: Abort following statement from SQLite Triggers
body: <p>I want to create a <a href="http://www.sqlite.org/lang_createtrigger.html" rel="nofollow">SQLite trigger</a> similar to this one:</p>
  
  <pre><code>CREATE TRIGGER "prevent_duplicate_emails"
  BEFORE INSERT OF "email" ON "users"
  FOR EACH ROW
  BEGIN
      SELECT COUNT("email") FROM "users" WHERE "email" LIKE NEW."email"
  
      # FIX ME!
      IF COUNT("email") &gt; 0:
          RAISE ABORT|FAIL, NEW."email" || ' already exists'
      ELSE:
          INSERT INTO "unique_emails" VALUES (NEW."email");
      ENDIF;
  END;
  </code></pre>
  
  <p>So basically when I do:</p>
  
  <pre><code>INSERT INTO "users" ("email") VALUES ("adam@eden.com"); # WORKS
  INSERT INTO "users" ("email") VALUES ("adam@eden.com"); # FAILS
  INSERT INTO "users" ("email") VALUES ("eve@eden.com"); # WORKS
  </code></pre>
  
  <p>The first <code>INSERT</code> will originate two new records (in tables <code>users</code> and <code>unique_emails</code>), while the second <code>INSERT</code> will fail and originate no records at all. Is it possible to do this from a trigger?</p>
  
  <p>I read the docs, but besides not fully understanding <code>RAISE</code> I don't see a way to achieve this.</p>
  
  <p><strong>PS</strong>: I know I could take several other approaches in order to get a list of unique emails, but that's not the point of this question. It would really simplify things if I could do this check / abort from within the trigger.</p>