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.nasedkin.perm@mail.ru