Skip to content

Instantly share code, notes, and snippets.

@edin-m
Forked from elyezer/ring_buffer.sql
Last active August 29, 2015 14:24
Show Gist options
  • Save edin-m/8aec20239125f9ad138f to your computer and use it in GitHub Desktop.
Save edin-m/8aec20239125f9ad138f to your computer and use it in GitHub Desktop.
-- Example table
CREATE TABLE ring_buffer (id INTEGER PRIMARY KEY AUTOINCREMENT, data TEXT);
-- Number 10 on where statement defines the ring buffer's size
CREATE TRIGGER delete_tail AFTER INSERT ON ring_buffer
BEGIN
DELETE FROM ring_buffer WHERE id%10=NEW.id%10 AND id!=NEW.id;
END;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment