On Thu, Jul 06, 2000 at 10:47:17AM -0500, Richard Wackerbarth wrote:
> On Thu, 06 Jul 2000, Shimpei Yamashita wrote:
> > On Wed, Jul 05, 2000 at 09:10:12PM -0500, Christopher Browne wrote:
> > > I would anticipate that having the basic representation be via
> > > rational numbers (e.g. - numerator + denominator in each entry) will
> > > _prevent_ using an SQL DBMS, because SQL DBMSes generally do not
> > > contemplate that representation.
> >
> > I do not understand why this would be the case. It is probably true that
> > most SQL DBMSes do not offer rational numbers as a data type, but you can
> > simulate one by having two integer columns per rational number to be
> > represented; row selection is atomic in DBMSes, so there shouldn't be any
> > problems with consistency.
> 
> The problems are that:
> 
> 1) You cannot have the database perform summations for you. You would be 
> required to extract every LE and perform the arithmetic in the engine.
> For small databases, this would not be too bad. However, any serious business 
> uses would make this too inefficient.

You should be able to do most, if not all, of the summation work within
the database. A summation algorithm would look like

  SELECT x = least_common_multiple(denominator) FROM table
  SELECT y = SUM(numerator*(x/denominator)) FROM table
  SELECT summation = y / x
  
so the worst you'll have to do is to implement least common multiple as a
stored procedure. Not very difficult, and shouldn't be too expensive
if most of the denominators are going to be the same, as you imply.

This may still cause performance problems--it is, after all, a heck of a
lot more work than just a simple summation--but it is not necessary to
drag any of the data out to the application layer.

> 2) If you assume that all of the denominators for a given currency are the 
> same, you have not really gained anything by storing them repeatedly. And you 
> have introduced an additional possibility of error trying to enforce the 
> assertion that they are the same.

True; however, this is a problem with the rational number representation
scheme, not the RDBM paradigm. You still have to decide at some point
whether you're going to assume all the denominators for a currency is
going to be the same, and the moment you make that decision, you're going
to run the risk of either wasting space or committing an error.

Shimpei.

-- 
Shimpei Yamashita                   <http://www2.gol.com/users/shimpei/>

--
Gnucash Developer's List
To unsubscribe send empty email to: [EMAIL PROTECTED]


Reply via email to