Re: Newbie question re SQL - Mailing list pgsql-general

From missive@frontiernet.net (Lee Harr)
Subject Re: Newbie question re SQL
Date
Msg-id slrna850fo.4a.missive@whave.frontiernet.net
Whole thread Raw
In response to Re: Newbie question re SQL  (missive@frontiernet.net (Lee Harr))
List pgsql-general
>>> Quan     Price       Cost
>>>====     =====       ====
>>>  300     125       37,500
>>>  500     135       67,500
>>> (100)     110      (13,125)  <-- how do you get this number?
>
> When I sell a security, to calculate the cost of the remaining
> identical securities, I must subtract from my total cost before the
> sale the number of units sold * their cost per unit (not their fair
> market value at the time of the sale).
>

I was reading recently that it can be helpful to access the
database _only_ through functions. Basically, create an API
for accessing your data. So you might create functions:

buy(id, quan, price)
sell(id, quan, price)

which would deal with your accounting situation.

Maybe you could keep a table with the to-date cost which
gets updated each time you buy() or sell()

You might also look at sourceforge.net as I remember reading
about an accounting system written for sql databases.
(Someone may already have scratched this itch :)





pgsql-general by date:

Previous
From: Patrick Welche
Date:
Subject: Re: oids vs. serial question
Next
From: knut.suebert@web.de
Date:
Subject: Re: oids vs. serial question