Received: from localhost (unknown [200.46.204.191]) by postgresql.org (Postfix) with ESMTP id 200522E389F for ; Fri, 4 Jan 2008 12:15:39 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.191]) (amavisd-maia, port 10024) with ESMTP id 23597-04 for ; Fri, 4 Jan 2008 12:15:32 -0400 (AST) Received: from outmail136004.authsmtp.co.uk (outmail136004.authsmtp.co.uk [62.13.136.4]) by postgresql.org (Postfix) with ESMTP id E8DA72E3254 for ; Fri, 4 Jan 2008 12:15:28 -0400 (AST) Received: from outmail128184.authsmtp.net (outmail128184.authsmtp.net [62.13.128.184]) by punt3.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id m04GFQ8Z066116; Fri, 4 Jan 2008 16:15:27 GMT Received: from [192.168.0.3] (81-6-228-215.dyn.gotadsl.co.uk [81.6.228.215]) (authenticated bits=0) by mail.authsmtp.com (8.13.8/8.13.8/Kp) with ESMTP id m04GFPbV051485; Fri, 4 Jan 2008 16:15:25 GMT Subject: Re: Partitioning documentation example From: Simon Riggs To: Bruce Momjian Cc: PostgreSQL-documentation In-Reply-To: <200801041527.m04FR7L19863@momjian.us> References: <200801041527.m04FR7L19863@momjian.us> Content-Type: text/plain Date: Fri, 04 Jan 2008 16:15:50 +0000 Message-Id: <1199463350.18598.121.camel@ebony.site> Mime-Version: 1.0 X-Mailer: Evolution 2.8.2 Content-Transfer-Encoding: 7bit X-Server-Quench: 420dc3e9-bae0-11dc-814e-001185d377ca X-AuthRoute: OCdxZQATClZOTQEd DAteCiNZVAwpPBRK HVkIKg5MJUcNSQVJ NksadBtFaAFbZ1hf HGQLW1xEUVt7WGZ/ aQ8fZQRDZFRMXQ10 UklMXVBXCwUmXBwF cWh+AH9ycgRCcHs+ ZEVhXT5fXkQuJkUo S1MGRDgGeGZhPDMC WEFcIh5UcAJLdhoR aVd4ByJDAzANdhox BRMyIzE2OzRZJ2xZ RQoQKF8UXU8XHzk6 Dx0SFDA3GUBt X-Authentic-SMTP: 61633235383639.squirrel.dmpriest.net.uk:787/Kp X-Report-SPAM: If SPAM / abuse - report it at: http://www.authsmtp.com/abuse X-Virus-Status: No virus detected - but ensure you scan with your own anti-virus system! X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200801/2 X-Sequence-Number: 4731 On Fri, 2008-01-04 at 10:27 -0500, Bruce Momjian wrote: > It seems to me it would be much clearer if we added a second example > that used to_char() to create the INSERT statement dynamically based on > NEW.logdate: > > CREATE OR REPLACE FUNCTION measurement_insert_trigger() > RETURNS TRIGGER AS $$ > BEGIN > EXECUTE 'INSERT INTO measurement_y' || to_char(NEW.logdate,'YYYY_mMM') || ' VALUES (NEW.*)'; > END; > $$ > LANGUAGE plpgsql; > > It will of course fail if the table does not exist, which I think is > what we want. This trigger function would not have to be modified when > new tables are added. I like your new trigger better than the old, but I am still uncomfortable with recommending we use triggers with COPY for performance reasons and we should add a caveat. -- Simon Riggs 2ndQuadrant http://www.2ndQuadrant.com