Received: from maia.hub.org (maia-2.hub.org [200.46.204.251]) by mail.postgresql.org (Postfix) with ESMTP id BCDC1B5DBE8 for ; Fri, 27 May 2011 11:18:23 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.251]) (amavisd-maia, port 10024) with ESMTP id 90145-08 for ; Fri, 27 May 2011 14:18:16 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from exprod7og104.obsmtp.com (exprod7og104.obsmtp.com [64.18.2.161]) by mail.postgresql.org (Postfix) with ESMTP id 16225B5DBD8 for ; Fri, 27 May 2011 11:18:15 -0300 (ADT) Received: from mail-fx0-f42.google.com ([209.85.161.42]) (using TLSv1) by exprod7ob104.postini.com ([64.18.6.12]) with SMTP ID DSNKTd+yp8YT6bnwYSRCxwD4hNVl7UV8WQQe@postini.com; Fri, 27 May 2011 07:18:17 PDT Received: by fxm1 with SMTP id 1so1620951fxm.15 for ; Fri, 27 May 2011 07:18:14 -0700 (PDT) Received: by 10.223.30.82 with SMTP id t18mr2403234fac.106.1306505894557; Fri, 27 May 2011 07:18:14 -0700 (PDT) Received: from [192.168.1.183] (dsl-hkibrasgw2-ff7ac300-240.dhcp.inet.fi [88.195.122.240]) by mx.google.com with ESMTPS id b26sm695992fak.0.2011.05.27.07.18.12 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 27 May 2011 07:18:13 -0700 (PDT) Message-ID: <4DDFB2A3.7080900@enterprisedb.com> Date: Fri, 27 May 2011 17:18:11 +0300 From: Heikki Linnakangas User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; fi-FI; rv:1.9.2.17) Gecko/20110510 Icedove/3.1.10 MIME-Version: 1.0 To: Emanuel CC: pgsql-bugs@postgresql.org Subject: Re: BUG #6043: Compilation PLpgsql Succesful but execution bad References: <201105271405.p4RE5Tid050879@wwwmaster.postgresql.org> In-Reply-To: <201105271405.p4RE5Tid050879@wwwmaster.postgresql.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-1.9 tagged_above=-5 required=5 tests=BAYES_00=-1.9 X-Spam-Level: X-Archive-Number: 201105/200 X-Sequence-Number: 30339 On 27.05.2011 17:05, Emanuel wrote: > postgres=# CREATE OR REPLACE FUNCTION p_() RETURNS TABLE (i int) AS $$ > DECLARE > BEGIN > SELECT * FROM p; --<<<-- here must ne RETURN QUERY .. > END; > $$ LANGUAGE plpgsql; > CREATE FUNCTION > postgres=# select p_(); > ERROR: query has no destination for result data > HINT: If you want to discard the results of a SELECT, use PERFORM instead. > CONTEXT: PL/pgSQL function "p_" line 4 at SQL statement > > I don't know if it's really a bug or a feature request. But seems that the > function compiles well without checking the existence of a RETURN QUERY. I > think the best in this cases is raise an error during compilation. Yeah, the PL/pgSQL compiler isn't smart enough to catch that at compilation time. It's easy to see that there's a RETURN missing from a simple function like that, but not so easy in general. For example: CREATE FUNCTION AS foo() RETURNS text $$ declare i int4; begin i := 0; loop IF i = 100 THEN RETURN 'done'; END IF end end; $$ LANGUAGE plpgsql; The compiler would have to determine that the loop never ends, or it would complain that there's no RETURN at the end. Many compilers for other languages do that kind of analysis, but it usually only results in a warning, and compilers sometimes get that wrong. I don't think it's worthwhile to do that, but of course, patches are welcome. -- Heikki Linnakangas EnterpriseDB http://www.enterprisedb.com