X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6AAF3DB222 for ; Fri, 28 Oct 2005 13:07:27 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 13311-06 for ; Fri, 28 Oct 2005 16:07:24 +0000 (GMT) Received: from iracema.dnscenter.com.br (iracema3.dnscenter.com.br [67.15.81.2]) by svr1.postgresql.org (Postfix) with ESMTP id 7B6C3DB200 for ; Fri, 28 Oct 2005 13:07:24 -0300 (ADT) Received: from cpanel by iracema.dnscenter.com.br with local (Exim 4.52) id 1EVWlE-0004i5-6P; Fri, 28 Oct 2005 13:07:20 -0300 Received: from 200.158.187.193 ([200.158.187.193]) by www.presserv.org (Horde MIME library) with HTTP; Fri, 28 Oct 2005 13:07:20 -0300 Message-ID: <20051028130720.jxoth8izb468k44s@www.presserv.org> Date: Fri, 28 Oct 2005 13:07:20 -0300 From: lucas@presserv.org To: daryl@brandywine.com Cc: pgsql-sql@postgresql.org Subject: Re: Fwd: Re: Referencing References: <20051028105908.onaegu44ynnog8os@www.presserv.org> <43624661.7000404@brandywine.com> In-Reply-To: <43624661.7000404@brandywine.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format="flowed" Content-Disposition: inline Content-Transfer-Encoding: 7bit User-Agent: Internet Messaging Program (IMP) H3 (4.0.3) X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - iracema.dnscenter.com.br X-AntiAbuse: Original Domain - postgresql.org X-AntiAbuse: Originator/Caller UID/GID - [32001 502] / [47 12] X-AntiAbuse: Sender Address Domain - presserv.org X-Source: X-Source-Args: X-Source-Dir: X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.952 required=5 tests=[AWL=0.075, NO_REAL_NAME=0.55, RCVD_IN_NJABL_PROXY=0.327] X-Spam-Score: 0.952 X-Spam-Level: X-Archive-Number: 200510/386 X-Sequence-Number: 23239 Quoting Daryl Richter : > It's hard to say without knowing more precisely what you are trying > to model, but I think this push you in the right direction: > > -- This table takes the place of both SEND and BUY > create table activity( > id serial primary key, > product_id integer, --references.... > value money > ); > > create table financial( > id serial primary key, > cred_deb smallint, > value money, > activity_id integer references activity > ); > > create table output( > id serial primary key, > client integer, --references clientes, > fiscal_number varchar(30), > print_date date, > activity_id integer references activity > ); > > create table input( > id serial primary key, > supplier integer, -- references suppliers, > employee varchar(30), > activity_id integer references activity > ); > > And then you do the following: > > create view buy > as > select > a.id, > b.id as "input_id", > a.product_id, > a.value > from > activity a > join input b on b.activity_id = a.id; > Okay, but references between (output/input) and ACTIVITY tables is 1 to N. OUTPUT/INPUT - 1 to ACTIVITY - N. And not N to 1 how the example. Then the reference field need to be on "ACTIVITY (send/buy)" table.