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 B9E28DB54D for ; Mon, 31 Oct 2005 15:58:34 -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 77026-09 for ; Mon, 31 Oct 2005 19:58:32 +0000 (GMT) Received: from iracema.dnscenter.com.br (iracema3.dnscenter.com.br [67.15.81.2]) by svr1.postgresql.org (Postfix) with ESMTP id 382E8DB586 for ; Mon, 31 Oct 2005 15:58:33 -0400 (AST) Received: from cpanel by iracema.dnscenter.com.br with local (Exim 4.52) id 1EWfnY-0007Re-26; Mon, 31 Oct 2005 16:58:28 -0300 Received: from 200.148.63.190 ([200.148.63.190]) by www.presserv.org (Horde MIME library) with HTTP; Mon, 31 Oct 2005 16:58:27 -0300 Message-ID: <20051031165827.50z4qeezsnms8kwk@www.presserv.org> Date: Mon, 31 Oct 2005 16:58:27 -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> <20051028130720.jxoth8izb468k44s@www.presserv.org> <4366471F.1020509@brandywine.com> In-Reply-To: <4366471F.1020509@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.583 required=5 tests=[AWL=-0.294, NO_REAL_NAME=0.55, RCVD_IN_NJABL_PROXY=0.327] X-Spam-Score: 0.583 X-Spam-Level: X-Archive-Number: 200510/399 X-Sequence-Number: 23252 Quoting Daryl Richter : > 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: > >> > > 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 > ); Yes, I think it was what I wanted. And how I check if a register in "Transfer" table is only referenciable by ONE table (OR "output" OR "input")?? Would I create a Trigger like: CREATE or REPLACE FUNCTION TG_output_check() RETURNS TRIGGER AS $$ BEGIN IF exists (select 1 from input where transfer_id=NEW.transfer_id) THEN Raise Exception 'This activity (transfer) is alread setted to INPUT'; END IF; RETURN NEW; END; $$ language 'plpgsql'; CREATE TRIGGER TG_output_check BEFORE INSERT or UPDATE on OUTPUT EXECUTE PROCEDURE TG_output_check(); CREATE or REP...--- and the some function to INPUT --- Or is there another way to check it? Thank you again.