Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hj2su-0000d1-UF for pgsql-general@arkaria.postgresql.org; Thu, 04 Jul 2019 14:38:53 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1hj2st-0006gB-Du for pgsql-general@arkaria.postgresql.org; Thu, 04 Jul 2019 14:38:51 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hj2st-0006g4-4M for pgsql-general@lists.postgresql.org; Thu, 04 Jul 2019 14:38:51 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1hj2sq-0007OF-GD for pgsql-general@lists.postgresql.org; Thu, 04 Jul 2019 14:38:50 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id x64EcghS028765; Thu, 4 Jul 2019 10:38:42 -0400 From: Tom Lane To: Andrey Sychev cc: pgsql-general@lists.postgresql.org Subject: Re: Error: rows returned by function are not all of the same row type In-reply-to: <851561973.20190704162046@cifrasoft.com> References: <851561973.20190704162046@cifrasoft.com> Comments: In-reply-to Andrey Sychev message dated "Thu, 04 Jul 2019 16:20:46 +0400" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <28763.1562251122.1@sss.pgh.pa.us> Date: Thu, 04 Jul 2019 10:38:42 -0400 Message-ID: <28764.1562251122@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Andrey Sychev writes: > I have written C-language function that returns > multiple composite rows. > Generally function works as expected, but sometimes problem takes place. > At rough guess the problem occurs when number of returning rows > relatively large (more than 100K - 1M). I do not think it's valid to return from your function with the SPI context still open. Probably, it seems to accidentally sort of work as long as you don't return enough rows to cause the outer query to do anything interesting like spill to disk. Probably you should re-code this to execute just once and return a tuplestore. regards, tom lane