X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (mx1.hub.org [200.46.208.251]) by postgresql.org (Postfix) with ESMTP id 2F32E9FB27E for ; Tue, 19 Sep 2006 20:54:21 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.208.251]) (amavisd-new, port 10024) with ESMTP id 69673-10 for ; Tue, 19 Sep 2006 20:54:14 -0300 (ADT) X-Greylist: from auto-whitelisted by SQLgrey- Received: from servata.com (ip-216-152-249-241.servata.com [216.152.249.241]) by postgresql.org (Postfix) with ESMTP id 3601D9FA2E6 for ; Tue, 19 Sep 2006 20:54:14 -0300 (ADT) Received: from [209.162.219.253] (helo=dogma.v10.wvs) by servata.com with esmtpa (Exim 4.50) id 1GPpPa-0003mq-TW; Tue, 19 Sep 2006 16:53:59 -0700 Subject: Re: Pipelined functions in Postgres From: Jeff Davis To: Milen Kulev Cc: 'Shoaib Mir' , pgsql-performance@postgresql.org In-Reply-To: <007b01c6dc31$ae395920$0a00a8c0@trivadis.com> References: <007b01c6dc31$ae395920$0a00a8c0@trivadis.com> Content-Type: text/plain Date: Tue, 19 Sep 2006 16:54:01 -0700 Message-Id: <1158710041.30652.116.camel@dogma.v10.wvs> Mime-Version: 1.0 X-Mailer: Evolution 2.0.4 (2.0.4-7) Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=0.224 tagged_above=0 required=5 tests=AWL, FORGED_RCVD_HELO, SPF_HELO_PASS X-Spam-Level: X-Archive-Number: 200609/263 X-Sequence-Number: 20949 On Tue, 2006-09-19 at 23:22 +0200, Milen Kulev wrote: > Hello Shoaib, > I know the SETOF funcitons. I want to simulate (somehow) > producer/consumer relationship with SETOF(pipelined) functions. The > first (producer )function generates records (just like your test_pipe > function), and the second function consumers the records , produced by > the first function. The second function can be rows/records producer > for another consumer functions e.g. it should looks like(or similar) > select * from consumer_function( producer_function(param1, > param2, ...)); > > What I want to achieve is to impelement some ETL logic > in consumer_functions (they could be chained, of course). > The main idea is to read source DWH tables once (in > producer_function, for example), and to process the rowsets > in the consumer functions. I want to avoid writing to intermediate > tables while performing ETL processing . > Is this possible with SETOF functions ? > Functions cannot take a relation as a parameter. Why not create a single function that does what you need it to do? You can write such a function in the language of your choice, including C, perl, PL/pgSQL, among others. That gives you a lot of power to do what you need to do in a single pass, without passing the results on to other functions. If you provide an example of what you need to be able to do maybe someone on this list knows a way to do it with one function call. Also, I'll point out that what you want to do is very similar to using typical relational constructs. Consider whether sub-selects or aggregates in conjunction with set-returning functions can achieve what you want. PostgreSQL is smart enough to only read the big table once if possible. Regards, Jeff Davis