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 336E9DB6A9 for ; Tue, 1 Nov 2005 10:43:26 -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 70412-03 for ; Tue, 1 Nov 2005 14:43:22 +0000 (GMT) Received: from svr4.postgresql.org (svr4.postgresql.org [66.98.251.159]) by svr1.postgresql.org (Postfix) with ESMTP id 3867EDB6A4 for ; Tue, 1 Nov 2005 10:43:23 -0400 (AST) Received: from website.brandywine.com (mailcheck.brandywine.com [146.145.113.9]) by svr4.postgresql.org (Postfix) with ESMTP id 3F6055AF7F1 for ; Tue, 1 Nov 2005 14:43:27 +0000 (GMT) X-eSCM-MailFrom: Received: from BAM_EXCHANGE (10.1.0.100) by website.brandywine.com (10.1.0.9); Tue, 01 November 2005 09:47:02 -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 R6ZYYSF3; Tue, 1 Nov 2005 09:42:35 -0500 Message-ID: <43677F75.9030409@brandywine.com> Date: Tue, 01 Nov 2005 09:45:09 -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> <4366471F.1020509@brandywine.com> <20051031165827.50z4qeezsnms8kwk@www.presserv.org> In-Reply-To: <20051031165827.50z4qeezsnms8kwk@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.043 required=5 tests=[AWL=0.043] X-Spam-Score: 0.043 X-Spam-Level: X-Archive-Number: 200511/2 X-Sequence-Number: 23254 lucas@presserv.org wrote: > 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. > Exactly, except for the small change that your trigger declaration needs "for each row" as shown below: CREATE TRIGGER TG_output_check BEFORE INSERT or UPDATE on output for each row EXECUTE PROCEDURE TG_output_check(); -- Daryl