Re: Implementing "thick"/"fat" databases - Mailing list pgsql-general

From David Johnston
Subject Re: Implementing "thick"/"fat" databases
Date
Msg-id B113914E-0E3D-41B9-ACE7-78B0BDE512DE@yahoo.com
Whole thread Raw
In response to Re: Implementing "thick"/"fat" databases  (Darren Duncan <darren@darrenduncan.net>)
List pgsql-general


I was assuming here that we were dealing with a double-entry accounting system where every line item in one account had a corresponding line item in another account of equal magnitude, and so all line items were in pairs, because you showed what looked like 1 pair, hence specifying the "50" once makes sense.

So are you wanting the 1 function to take a set of line-item pairs, or are you wanting to say do +50 in one account and -25 in each of 2 different accounts, as a total of 3 line items?  If the former, I would still just specify the "50" once and have a set of {from, to, amount} triples as an argument, which would be relation/rowset-typed.  If the latter, then you would specify the "50" twice.

A little OT but all double-entry accounting requires is that the debits and credits of an entry - when totaled - equal zero (are equal); there is no requirement pertaining to each item having an equal but opposite counter-part.  Nor are multiple accounts required; some ad-hoc entries simply "re-class" money within a single account so that different "controls" and/or amounts remain.

Ideally what you would want is a type called "accounting detail entry" which represents a credit/debit.  For the function you can either make any "negative" amounts credits OR pass in two arrays - one for debits and one for credits.  Either way you'd pass in an array of this "accounting detail entry" type along with information such as accounting date and journal number.  To avoid using a type I would make a "create_entry" function that you'd use to create the detail items on a staging table, attached to a specific ID, and then create the final entry by calling the original function with user/date/journal/etc information and reference the detail records via the ID.

David J.


pgsql-general by date:

Previous
From: "Karl Nack"
Date:
Subject: Re: Implementing "thick"/"fat" databases
Next
From: Chris Travers
Date:
Subject: Re: Implementing "thick"/"fat" databases