Received: from localhost (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id 1BB9F64FC66 for ; Fri, 21 Nov 2008 07:53:49 -0400 (AST) Received: from mail.postgresql.org ([200.46.204.86]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 34140-09 for ; Fri, 21 Nov 2008 07:53:44 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from zimbra.linuxsilo.net (zimbra.linuxsilo.net [92.48.122.79]) by mail.postgresql.org (Postfix) with ESMTP id 21DEF64FC5E for ; Fri, 21 Nov 2008 07:53:44 -0400 (AST) Received: from localhost (localhost.localdomain [127.0.0.1]) by zimbra.linuxsilo.net (Postfix) with ESMTP id F2ED32A664 for ; Fri, 21 Nov 2008 11:53:41 +0000 (GMT) X-Virus-Scanned: amavisd-new at Received: from zimbra.linuxsilo.net ([127.0.0.1]) by localhost (zimbra.linuxsilo.net [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 3Q7qSVvFR7WK for ; Fri, 21 Nov 2008 11:53:41 +0000 (GMT) Received: from zimbra.linuxsilo.net (zimbra.linuxsilo.net [92.48.122.79]) by zimbra.linuxsilo.net (Postfix) with ESMTP id 8B9672A661 for ; Fri, 21 Nov 2008 11:53:41 +0000 (GMT) Date: Fri, 21 Nov 2008 11:53:41 +0000 (GMT) From: Jaume Sabater To: pgsql-admin@postgresql.org Message-ID: <3481767.6501227268421440.JavaMail.root@zimbra.linuxsilo.net> In-Reply-To: <29176653.6481227268381440.JavaMail.root@zimbra.linuxsilo.net> Subject: Variable table name in a trigger function or in a rule MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Originating-IP: [212.170.239.110] X-Mailer: Zimbra 5.0.10_GA_2609.DEBIAN4.0 (ZimbraWebClient - FF3.0 (Win)/5.0.10_GA_2609.DEBIAN4.0) X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0 tagged_above=0 required=5 tests=none X-Spam-Level: X-Archive-Number: 200811/131 X-Sequence-Number: 30785 Hi everyone! I presume that this problem must have been discussed many times, but I have not been able to find a solution in the archives of this list or googling. This is the situation: - I have partitioned 1 table into 10 tables, being the check constraint the language id, and activated "constraint_exclusion" in postgresql.conf. Child tables do not add new columns to those inherited. - Parent table is TTopographyLevels. Child tables are TTopographyLevels_en, TTopographyLevels_es, and so on. They have primary keys and indexes where required, as per the online documentation. - I've created 3 triggers (insert, update and delete) on the parent table to distribute the data accordingly. Questions/doubts: 1. Inside the triggers, table name is variable (in the three of them), depending on the check constraint. I have not find a way to have just one query, parametrized, so that I don't end up with a VERY long trigger function. I had to use the EXECUTE command. I understand that the reason why it is not possible to precompile a function without knowing the table name at that time. Still, this problem must be very common to everyone using partitioning. Therefore, given how important the process of "redistributing" the row to the appropriate child table is, I presume that I should end up with a very long function, plenty of if..elseif..else statements, which does not use the EXECUTE command. Correct? 2. Rules or triggers. I've read a lot about it and there are two points I have to consider: 2.1. When we use the COPY command for the initial bulk import, rules will be disabled, therefore the information will all end up in the parent table. But there is no way not to disable rules when running a COPY command, correct? So it's a no-go for me. It's gotta be triggers, it seems. 2.2. On the other hand, we will be doing lots of updates every night (reads during the day, mostly), and evaluating the rule once per transaction instead of executing the trigger once per row seems like very good news. So I was wonderig: this must be a very common situation for EVERYONE partitioning tables. Which is the most common approach for the case? At the moment, after reading all I've read, and given my case, it's very long triggers with no EXECUTE statements, but I'd like to hear opinions and get some feedback, if possible. Thanks. -- Jaume Sabater http://linuxsilo.net/ "Ubi sapientas ibi libertas"