Skip to content

Instantly share code, notes, and snippets.


DRMacIver/posts.sql Secret

Created Nov 13, 2009
What would you like to do?
create table unfiltered_posts(id int primary key default nextval('post_ids'),
body text,
deleted boolean not null default false);
create view posts as select * from unfiltered_posts where not deleted;
create or replace rule insert_into_posts as
on insert to posts do instead
insert into unfiltered_posts
values(coalesce(, nextval('post_ids')),
coalesce(NEW.deleted, false));
create or replace rule update_to_posts as
on update to posts do instead
update unfiltered_posts
set id = coalesce(,,
body = coalesce(NEW.body, OLD.body),
deleted = coalesce(NEW.deleted, OLD.deleted)
where id =;
create or replace rule delete_posts as
on delete to posts do instead
update unfiltered_posts
set deleted = true where id =;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment