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 118F7DB52F for ; Mon, 31 Oct 2005 12:31:19 -0400 (AST) 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 60169-05 for ; Mon, 31 Oct 2005 16:31:17 +0000 (GMT) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by svr1.postgresql.org (Postfix) with ESMTP id 4CD9EDB541 for ; Mon, 31 Oct 2005 12:31:16 -0400 (AST) Received: from website.brandywine.com (mailcheck.brandywine.com [146.145.113.9]) by svr4.postgresql.org (Postfix) with ESMTP id 006815AF647 for ; Mon, 31 Oct 2005 16:31:15 +0000 (GMT) X-eSCM-MailFrom: Received: from BAM_EXCHANGE (10.1.0.100) by website.brandywine.com (10.1.0.9); Mon, 31 October 2005 11:34:21 -0400 Received: from [10.1.0.60] (gen-wayne [10.1.0.60]) by bam_exchange.brandywine.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id R6ZYYRP4; Mon, 31 Oct 2005 11:29:57 -0500 Message-ID: <4366471F.1020509@brandywine.com> Date: Mon, 31 Oct 2005 11:32:31 -0500 From: Daryl Richter Reply-To: daryl@brandywine.com Organization: Brandywine Asset Management User-Agent: Mozilla Thunderbird 1.0.6 (Windows/20050716) X-Accept-Language: en-us, en MIME-Version: 1.0 To: lucas@presserv.org Cc: pgsql-sql@postgresql.org Subject: Re: Fwd: Re: Referencing References: <20051028105908.onaegu44ynnog8os@www.presserv.org> <43624661.7000404@brandywine.com> <20051028130720.jxoth8izb468k44s@www.presserv.org> In-Reply-To: <20051028130720.jxoth8izb468k44s@www.presserv.org> Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.045 required=5 tests=[AWL=0.045] X-Spam-Score: 0.045 X-Spam-Level: X-Archive-Number: 200510/396 X-Sequence-Number: 23249 lucas@presserv.org wrote: > 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: >> [snipped old schema] > > 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. > Ahh, ok. In that case I reverse it like so: -- This table hold everything in common for inputs/outputs create table transfer( id serial primary key ); create table output( transfer_id int primary key references transfer, client integer, --references clientes, fiscal_number varchar(30), print_date date ); create table input( transfer_id int primary key references transfer, supplier integer, -- references suppliers, employee varchar(30) ); create table activity( id serial primary key, transfer_id int references transfer, product_id integer, --references.... value money ); create table financial( id serial primary key, cred_deb smallint, value money, activity_id integer references activity ); create view buy as select a.id as "input_id", -- or buy_id, etc. ... b.supplier, b.employee, c.id as "activity_id", c.product_id, c.value from transfer a join input b on b.transfer_id = a.id join activity c on c.transfer_id = a.id; If this is still not what you're after and you would like additional assistance, it would really help to have at least a few rows of sample data. Good luck! -- Daryl Richter Platform Author & Director of Technology (( Brandywine Asset Management ) ( "Expanding the Science of Global Investing" ) ( http://www.brandywine.com ))