Re: Running Totals and other stuff....

From: Richard Huxton <dev(at)archonet(dot)com>
To: Jerry LeVan <jerry(dot)levan(at)eku(dot)edu>
Cc: pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Running Totals and other stuff....
Date: 2004-06-01 14:42:51
Message-ID: 40BC95EB.8040704@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jerry LeVan wrote:
> Yes, my mail server has a dynamic IP it is running
> on my Mac...
>
> I am retired and the University let me keep my mailbox,
> I tried using the Universities Exchange Server to send
> the message you responded to below, much to my chagrin,
> the server wraps *all* outgoing mail in html.

My sympathies, sir.

> My check table does not have a key, ( it does not
> have a lot of entries ~3200 in four years).

Whether 3200, 32 or 0 rows you should have a key...

> I generate the data in the table by exporting transactions
> from Quicken and parse the QIF file to a csv file and then
> import via COPY to the database.
>
> As I noted just using the date field does not quite work
> because there are multiple transactions on the same date.

And without a key there's no way to solve the issue, since there's no
way to distinguish one row from another.

> Is there a way to add an increasing sequence of unique
> integers as a temporary column?

To cut a long story short - you need a primary key. If your table has no
suitable candidates, you will have to add one. (Can you not use
cheque-number?)

If you add your own, I would recommend adding a column of type SERIAL.
This is basically an integer with an attached sequence generator, so if
no value is supplied it defaults to the next number supplied by the
sequence.

You can continue to use COPY to import new data, just don't mention the
new column in the list to insert and it will be given the default.

You can then order by date, <key> and that will let you calculate your
running total.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-general by date

  From Date Subject
Next Message zhicheng wang 2004-06-01 14:51:39 Re: after using pg_resetxlog, db lost
Previous Message Alan Graham 2004-06-01 14:41:33 Re: Running Totals and other stuff....