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 1h1XXl-0006Qv-Hu for pgsql-general@arkaria.postgresql.org; Wed, 06 Mar 2019 14:29:13 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1h1XXj-0003aC-MM for pgsql-general@arkaria.postgresql.org; Wed, 06 Mar 2019 14:29:11 +0000 Received: from makus.postgresql.org ([2001:4800:3e1:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h1XXj-0003UB-8l for pgsql-general@lists.postgresql.org; Wed, 06 Mar 2019 14:29:11 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.89) (envelope-from ) id 1h1XXe-000425-KD for pgsql-general@lists.postgresql.org; Wed, 06 Mar 2019 14:29:09 +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 x26ET3KS016225; Wed, 6 Mar 2019 09:29:03 -0500 From: Tom Lane To: Rob Sargent cc: "pgsql-generallists.postgresql.org" Subject: Re: query has no destination for result data In-reply-to: References: Comments: In-reply-to Rob Sargent message dated "Tue, 05 Mar 2019 23:45:50 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-ID: <16223.1551882543.1@sss.pgh.pa.us> Content-Transfer-Encoding: quoted-printable Date: Wed, 06 Mar 2019 09:29:03 -0500 Message-ID: <16224.1551882543@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Rob Sargent writes: > One of my plpgsql functions is now throwing this error: > ERROR: query has no destination for result data > HINT: If you want to discard the results of a SELECT, use PERFORM inste= ad. > CONTEXT: PL/pgSQL function optimal_pvalue_mono(text,text,integer,double= precision,integer) line 65 at SQL statement > The code referenced at line 65 is the last line in a "for row in query=E2= =80=9D construct as follows: > 54 for segp in > 55 select s.id, s.firstmarker, s.lastmarker, = > 56 v.ipv, > 57 array_length(p.probands,1) as pbs, > 58 s.lastmarker - s.firstmarker as mks > 59 from segment s = > 60 join imputed_pvalue_t v on s.id =3D v.segment_id > 61 join probandset p on s.probandset_id =3D p.id > 62 join probandset_group_member m on p.id =3D m.member_id > 63 where s.markerset_id =3D mkset > 64 and m.group_id =3D pbsgid > 65 order by ipv, pbs, mks > 66 LOOP I think perhaps you've miscounted lines somehow, or are looking into the wrong function. The "at SQL statement" bit indicates that plpgsql thinks it's dealing with a run-of-the-mill SQL command, not a FOR loop; moreover, looking at the source code shows that "query has no destination for result data" is thrown only in exec_stmt_execsql, which ditto. Another possibility, perhaps, is that there's some syntax error a little bit above what you've shown us, such that this stanza isn't being seen as a FOR loop at all, but as more lines in a SQL command that started earlier. I'm not entirely sure how such a case would have got past parsing and into execution, but it's worth thinking about. In any case, this isn't solvable with just what you've shown us here. regards, tom lane