Skip to content

Instantly share code, notes, and snippets.

@aditya
aditya / accounting.sql
Created September 15, 2021 04:39 — forked from 001101/accounting.sql
Basic double-entry bookkeeping system, for PostgreSQL.
CREATE TABLE accounts(
id serial PRIMARY KEY,
name VARCHAR(256) NOT NULL
);
CREATE TABLE entries(
id serial PRIMARY KEY,
description VARCHAR(1024) NOT NULL,
amount NUMERIC(20, 2) NOT NULL CHECK (amount > 0.0),
-- Every entry is a credit to one account...
@aditya
aditya / gist:36742
Created December 16, 2008 19:31 — forked from mage2k/gist:36737
begin;
select count(*)
from actions
where item_type='Story'
and item_published_at is not null;
select count(distinct(item_id))
from actions
where item_type='Story'