X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id A15C3528B7 for ; Tue, 2 Aug 2005 21:55:01 -0300 (ADT) 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 60944-06 for ; Wed, 3 Aug 2005 00:55:00 +0000 (GMT) Received: from mail.travelamericas.com (unknown [206.130.134.147]) by svr1.postgresql.org (Postfix) with SMTP id 8DD1252894 for ; Tue, 2 Aug 2005 21:54:57 -0300 (ADT) Received: (qmail 670 invoked from network); 3 Aug 2005 00:54:59 -0000 Received: from unknown (HELO ?10.0.0.253?) (10.0.0.253) by verkiel.travelamericas.com with SMTP; 3 Aug 2005 00:54:59 -0000 Message-ID: <42F015E3.8070308@travelamericas.com> Date: Tue, 02 Aug 2005 17:54:59 -0700 From: Chris Travers User-Agent: Mozilla Thunderbird 1.0 (X11/20041206) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Kyle Bateman , pgsql-sql Subject: Re: Trigger on select? References: <42F01AAF.6040903@actarg.com> In-Reply-To: <42F01AAF.6040903@actarg.com> 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, hits=0.044 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO X-Spam-Level: X-Archive-Number: 200508/13 X-Sequence-Number: 22241 Kyle Bateman wrote: > Hey, anyone know if it is possible to fire a trigger before a select? > I'm considering creating some tables which contain data summarized > from other tables as kind of a cache mechanism. The hope is I can > speed up some queries that get executed a lot (and are kind of slow) > by maintaining data (like sums of big columns, for example). I was > all ready to go and then I discovered that trigger-before-select is > not supported. (Is it in any DB?) > > The idea is this: > > Any time I execute a query that would access the summary data, the > "before select" trigger fires and goes out and builds any summary data > missing from the summary table. No. You must instead generate a view. > When I do an insert,update,delete on the primary data table, another > trigger fires that removes the applicable data from the summary > table. This way, I only cache the information I need in the summary > table, right before I need it. But it can stay there as long as the > base information doesn't change so I don't have to redo the expensive > operation of summarizing it any more often than necessary. Its kind > of like an index in a way, but it is not maintained at insert/update > time. Rather, it is updated as it is needed. > > Anyone have any ideas about how I can accomplish this? something like create view wrapper_table as select * from original table where (select pseudo_trigger_function()) IS TRUE; The above example is off the top of my head. It may require some editing. Best Wishes, Chris Travers Metatron Technology Consulting