Re: Debet-Credit-Balance Calculation

From: Mihail Nasedkin <m(dot)nasedkin(dot)perm(at)mail(dot)ru>
To: "Muhyiddin A(dot)M Hayat" <middink(at)indo(dot)net(dot)id>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: Debet-Credit-Balance Calculation
Date: 2005-04-20 02:28:58
Message-ID: 1412347250.20050420082858@mail.ru
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

I think you forget FOREIGN KEY:
transactions.trx_type_id -> trx_type.id

MAMH> Dear All,

MAMH> I have problem to calculation
MAMH> balance from debet and credit.

MAMH> my transaction table:
...
MAMH> CREATE TABLE "public"."transactions" (
MAMH>  
MAMH> "id" SERIAL,
MAMH>   "trx_timestamptz" TIMESTAMP(0) WITH TIME ZONE DEFAULT
MAMH> ('now'::text)::timestamp(6) with time zone NOT NULL,
MAMH>   "account"
MAMH> CHAR(16) NOT NULL,
MAMH>   "trx_type_id" INTEGER NOT NULL,
MAMH>  
MAMH> "amount" NUMERIC(15,2) DEFAULT 0 NOT NULL,
MAMH>   "uid" INTEGER NOT NULL,
MAMH>   CONSTRAINT "transactions_pkey" PRIMARY KEY("id")
MAMH> ) WITH
MAMH> OIDS;
...

MAMH> and transaction type :
...
MAMH> CREATE TABLE "public"."trx_type" (
MAMH>   "id" SERIAL,
MAMH>   "trx_name" VARCHAR(32),
MAMH>   "t_type" CHAR(2),
MAMH>  
MAMH> CONSTRAINT "trx_type_pkey" PRIMARY KEY("id"),
MAMH>   CONSTRAINT
MAMH> "trx_typei_check0" CHECK ((t_type = 'CR'::bpchar) OR (t_type =
MAMH> 'DB'::bpchar))
MAMH> ) WITH OIDS;  

MAMH> ---------------------------------------------------------------------

MAMH> so, i'm using this query:

...
MAMH> ... query eat all my cpu process and take a long time ...

--
regards,
Mihail mailto:m(dot)nasedkin(dot)perm(at)mail(dot)ru

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Christopher Browne 2005-04-20 03:14:10 Re: Debet-Credit-Balance Calculation
Previous Message Jaime Casanova 2005-04-19 23:03:35 Re: trying to do an update a bit confused.