X-Original-To: pgsql-novice-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 0EB303CBD61; Fri, 17 Dec 2004 05:44:36 +0000 (GMT) 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 77055-02; Fri, 17 Dec 2004 05:44:25 +0000 (GMT) Received: from davinci.ethosmedia.com (server226.ethosmedia.com [209.128.84.226]) by svr1.postgresql.org (Postfix) with ESMTP id 747F83CBD9B; Fri, 17 Dec 2004 05:44:24 +0000 (GMT) Received: from [63.195.55.98] (account josh@agliodbs.com HELO spooky) by davinci.ethosmedia.com (CommuniGate Pro SMTP 4.1.8) with ESMTP id 6796846; Thu, 16 Dec 2004 21:45:59 -0800 From: Josh Berkus Organization: Aglio Database Solutions To: pgsql-sql@postgresql.org, KeithW@narrowpathinc.com Subject: Re: FUNCTION, TRIGGER and best practices Date: Thu, 16 Dec 2004 21:43:32 -0800 User-Agent: KMail/1.6.2 Cc: "PostgreSQL Novice" References: <20041217040520.M87972@narrowpathinc.com> In-Reply-To: <20041217040520.M87972@narrowpathinc.com> MIME-Version: 1.0 Content-Disposition: inline Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit Message-Id: <200412162143.32610.josh@agliodbs.com> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.009 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200412/136 X-Sequence-Number: 11713 Keith, > Can triggers and functions have the same name? Yes. > Is this a good practice? It can be. If the function does nothing but power the trigger, sure. Or you can use prefixes or suffixes to distinguish them. For example, if you had an audit trigger on the companies table, you might call the function audit_companies_tf, the trigger audit_companies_tg. > Where should the function and trigger be stored? Um, in the database? > In the same schema as the table they are connected to? I'm not sure you CAN put the trigger in a different schema from the table. It's a dependant object. > I will now be attempting to expand this function to move data from two > source tables to four or more target tables. (Different source columns go > to different tables.) Is it possible to do a transaction/commit/rollback > inside a function that is driven by a trigger so that if any portion of the > transfer fails it is all rolled back? Well, if any portion of a trigger fails, everything is rolled back; so is the insert, for a before trigger. So that might be the way to handle the double-trigger situation .... except they'll be in two different tables, yes? So that'll require an explicit transaction wrapping the two inserts. -- Josh Berkus Aglio Database Solutions San Francisco