restruct cash table

From: Gerhard Heift <ml-postgresql-20081012-3518(at)gheift(dot)de>
To: pgsql-general(at)postgresql(dot)org
Subject: restruct cash table
Date: 2008-11-07 08:44:28
Message-ID: 20081107084427.GA6158@toaster.kawo1.rwth-aachen.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,

I have a small problem with my table: I have a table for my cash and i
do several actions in it. I receive money in different forms, I expend
money in different forms etc. And do each action I have various foreign
keys. But they are not all in use in every column. I don't know how I
can structure the table better:

CREATE TABLE cash (
id serial,
type text NOT NULL,
account text NOT NULL,
value numeric(10,2) NOT NULL,
item text,
department text,
person text,
description text
);

In this table is data like this:

ID | type | account | value | item | department | client |
---+----------+---------+---------+-------+--------------+----------+
1 | sale | acc_1 | 10,00 | paper | department_1 | NULL |
2 | deposit | acc_1 | 15,00 | NULL | NULL | client_1 |
3 | deposit | acc_2 | 25,00 | NULL | NULL | client_2 |
4 | transfer | acc_2 | -15,00 | NULL | NULL | NULL |
5 | transfer | acc_1 | 15,00 | NULL | NULL | NULL |
6 | purchase | acc_2 | -12,00 | NULL | department_3 | NULL |
7 | usage | NULL | -1,00 | page | | client_1 |
8 | usage | NULL | 1,00 | page | department_2 | NULL |
9 | usage | NULL | -1,00 | page | department_1 | NULL |
10 | usage | NULL | 1,00 | page | department_2 | NULL |

Is there a better way to store this actions?
(type, account, item, department and client have all its own tables)

Thanks,
Gerhard

Browse pgsql-general by date

  From Date Subject
Next Message Thomas Kellerer 2008-11-07 10:15:07 UPDATE tuples with a sub-select
Previous Message pcreso 2008-11-07 01:44:42 Specifying text to substitute for NULLs in selects