Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fBGNa-0000Ge-El for pgsql-sql@arkaria.postgresql.org; Wed, 25 Apr 2018 09:06:22 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.89) (envelope-from ) id 1fBGNY-0004bJ-Pz for pgsql-sql@arkaria.postgresql.org; Wed, 25 Apr 2018 09:06:20 +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_SHA384:256) (Exim 4.89) (envelope-from ) id 1fBGNY-0004b6-JD for pgsql-sql@lists.postgresql.org; Wed, 25 Apr 2018 09:06:20 +0000 Received: from hub.ringways.co.uk ([88.211.105.30] helo=ringways.co.uk) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1fBGNS-0007R9-6Q for pgsql-sql@lists.postgresql.org; Wed, 25 Apr 2018 09:06:19 +0000 Received: from eddie.ringways.co.uk ([10.1.1.115]) by ringways.co.uk with esmtp (Exim 4.89) (envelope-from ) id 1fBGNP-000Egq-Hl for pgsql-sql@lists.postgresql.org; Wed, 25 Apr 2018 10:06:12 +0100 From: Gary Stainburn Organization: Ringways Garages Ltd To: pgsql-sql@lists.postgresql.org Subject: error in function, works when typed Date: Wed, 25 Apr 2018 10:06:11 +0100 User-Agent: KMail/1.9.10 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Content-Disposition: inline Message-Id: <201804251006.11072.gary.stainburn@ringways.co.uk> X-KLMS-Rule-ID: 1 X-KLMS-Message-Action: clean X-KLMS-AntiSpam-Lua-Profiles: 124029 [Apr 25 2018] X-KLMS-AntiSpam-Version: 5.8.1.0 X-KLMS-AntiSpam-Envelope-From: gary.stainburn@ringways.co.uk X-KLMS-AntiSpam-Rate: 0 X-KLMS-AntiSpam-Status: not_detected X-KLMS-AntiSpam-Method: none X-KLMS-AntiSpam-Info: LuaCore: 128 128 d7aa645f57ce6a6ceb7dd78eb333137e5e6b654c, {msgid_created_by_recepient}, eddie.ringways.co.uk:7.1.1;d41d8cd98f00b204e9800998ecf8427e.com:7.1.1;127.0.0.199:7.1.2;ringways.co.uk:7.1.1, DmarcAF: none X-KLMS-AntiSpam-Interceptor-Info: scan successful X-KLMS-AntiPhishing: Clean, 2018/04/16 12:23:15 X-KLMS-AntiVirus: Kaspersky Security 8.0 for Linux Mail Server, version 8.0.1.721, bases: 2018/04/25 02:31:00 #8451410 X-KLMS-AntiVirus-Status: Clean, skipped X-Spam-Score: -50.8 (--------------------------------------------------) X-Spam-Report: Spam detection software, running on the system "ollie2.ringways.co.uk", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see Gary Stainburn for details. Content preview: I am writing a function to clear down old jobs. As you can see below, the commands work when I type them in, but when I try to use them in a function, the insert fails. Anyone got an idea why? The error suggests that the select does not have a destination, but it feeds the insert. [...] Content analysis details: (-50.8 points, 15.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -50 ALL_TRUSTED Passed through trusted hosts only via SMTP 0.1 SCORE_RCPTS Adding score for each recipient -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 1.0 RING_SAFE No description available. List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk I am writing a function to clear down old jobs. As you can see below, the commands work when I type them in, but when I try to use them in a function, the insert fails. Anyone got an idea why? The error suggests that the select does not have a destination, but it feeds the insert. ---- create or replace function service_cleardown(SRID integer, UID integer) RETURNS integer as $$ DECLARE ROWCOUNT integer; BEGIN select count(sr_id) into ROWCOUNT from service_receptions where sr_id = SRID; IF NOT FOUND THEN raise exception 'Reception ID invalid'; END IF; insert into service_jobs_log (sj_id, sj_u_id, sj_text) select sj_id, UID,'Job cleared down' from service_jobs where sj_date < CURRENT_DATE and sj_sr_id = SRID and sj_state < 90; update service_jobs set sj_state=90 where sj_date < CURRENT_DATE and sj_sr_id = SRID and sj_state < 90 returning ROWCOUNT; RETURN ROWCOUNT; END $$ LANGUAGE plpgsql; ---- goole=# insert into service_jobs_log (sj_id, sj_u_id, sj_text) select sj_id, 25,'Job cleared down' from service_jobs where sj_date < CURRENT_DATE and sj_sr_id = 10 and sj_state < 90; INSERT 0 0 goole=# update service_jobs set sj_state=90 where sj_date < CURRENT_DATE and sj_sr_id = 10 and sj_state < 90; UPDATE 0 goole=# select service_cleardown(10,25); ERROR: query has no destination for result data CONTEXT: PL/pgSQL function "service_cleardown" line 11 at SQL statement goole=#