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 1C19DD1C921 for ; Thu, 31 Jul 2003 22:31:25 +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 86023-06 for ; Thu, 31 Jul 2003 19:30:18 -0300 (ADT) Received: from dyatel.antar.bryansk.ru (dyatel.antar.bryansk.ru [80.237.18.85]) by svr1.postgresql.org (Postfix) with ESMTP id 08A7FD1C4EB for ; Thu, 31 Jul 2003 19:31:23 -0300 (ADT) Received: from fduch by dyatel.antar.bryansk.ru with local (Exim 4.20) id 19iLyM-000L2m-1F for pgsql-sql@postgresql.org; Fri, 01 Aug 2003 02:32:34 +0400 Date: Fri, 1 Aug 2003 02:32:33 +0400 From: "Alexander M. Pravking" To: pgsql-sql@postgresql.org Subject: Problem with looping on a table function result Message-ID: <20030731223233.GJ86626@dyatel.antar.bryansk.ru> Mime-Version: 1.0 Content-Type: text/plain; charset=koi8-r Content-Disposition: inline User-Agent: Mutt/1.4.1i X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/490 X-Sequence-Number: 14604 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? Thanks for your help. -- Fduch M. Pravking