X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id E00C0D1C9DD for ; Mon, 4 Aug 2003 09:26:21 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 00517-09 for ; Mon, 4 Aug 2003 06:25:08 -0300 (ADT) Received: from fzkmail2.fzk.de (fzkmail2.fzk.de [141.52.27.52]) by svr1.postgresql.org (Postfix) with SMTP id E0C9DD1C9DB for ; Mon, 4 Aug 2003 06:26:09 -0300 (ADT) Received: FROM resy5.fzk.de BY fzkmail2.fzk.de ; Mon Aug 04 11:26:11 2003 +0200 Received: œby rodos.fzk.de with ESMTP (8.8.6 (PHNE_17135)/8.7.1) id LAA06729; Mon, 4 Aug 2003 11:26:08 +0200 (METDST) Message-ID: <3F2E26AF.627C4763@rodos.fzk.de> Date: Mon, 04 Aug 2003 11:26:08 +0200 From: Christoph Haller X-Mailer: Mozilla 4.77 [en] (X11; U; HP-UX B.10.20 9000/780) X-Accept-Language: en MIME-Version: 1.0 To: pgsql-sql@postgresql.org, fduch@antar.bryansk.ru Subject: Re: Problem with looping on a table function result Content-Type: text/plain; charset=iso-8859-2 Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Amavis-Alert: BAD HEADER Non-encoded 8-bit data (char 9C hex) in message header 'Received' Received: \234by rodos.fzk.de... ^ X-Archive-Number: 200308/27 X-Sequence-Number: 14643 > > I've met the following problem. > I had successfully written a function divide_into_days(timestamp, timestamp) > which returns setof (timestamp, timestamp) pairs - a list of days the > given interval is divided into. > > What I want is to use each record from resultset to pass to another > function, something like: > > SELECT days.*, summary_stats(days.day_start, days.day_end) > FROM divide_into_days('2003-06-01', '2003-07-01') days; > > The problem is that summary_stats function returns a record, so I have > to use SELECT * FROM summary_stats(...). I can't use the following too: > > SELECT * > FROM summary_stats(days.day_start, days.day_end) stats, > divide_into_days('2003-06-01', '2003-07-01') days; > > (there was a discussion a few days ago about using subselects, > but here's a slightly different case). > > I wonder if where's a way to do the trick without writing one more > PL/PgSQL table function doing FOR row IN SELECT ... LOOP or using > client-side loop? > Did you see http://techdocs.postgresql.org/guides/SetReturningFunctions Regards, Christoph