Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ncuGy-000668-91 for pgsql-general@arkaria.postgresql.org; Fri, 08 Apr 2022 19:27:56 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.92) (envelope-from ) id 1ncuGw-0002LK-8j for pgsql-general@arkaria.postgresql.org; Fri, 08 Apr 2022 19:27:54 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ncuGu-0002Jf-NW for pgsql-general@lists.postgresql.org; Fri, 08 Apr 2022 19:27:53 +0000 Received: from out5-smtp.messagingengine.com ([66.111.4.29]) by magus.postgresql.org with esmtps (TLS1.3:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1ncuGq-0001ue-ER for pgsql-general@lists.postgresql.org; Fri, 08 Apr 2022 19:27:52 +0000 Received: from compute5.internal (compute5.nyi.internal [10.202.2.45]) by mailout.nyi.internal (Postfix) with ESMTP id 7706A5C0103; Fri, 8 Apr 2022 15:27:45 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute5.internal (MEProxy); Fri, 08 Apr 2022 15:27:45 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aklaver.com; h= cc:content-transfer-encoding:content-type:date:date:from:from :in-reply-to:in-reply-to:message-id:mime-version:references :reply-to:sender:subject:subject:to:to; s=fm3; bh=vYgKsyC6Ta2sKP oC3Utkwzx7mzKbbTtOTLLZLn4sQvs=; b=CEntYTles+hzFUfDLRF3ADsOlC60z/ lR+VnZ0DJFES/S20oM+Tnh/4vPxyNNKKczmL81pVGltsUH8Fa/AMqZY0SPRQUGIU IPlBaIFHKpNnf98yR4KmLbp7VjDkxrG/g84CyUvzam9tSOtIH4rcX13AVEUQbamB 1N0OllYWKeBlQm4lUDNPcUO6rAb36E/l5i5eqeR2nsBxsPFF2dOEPtBF1xe8RGLd DsaTyzbCa5OTrjhwI70nlKFcun379Uh9L7EX0oBQ05kWf5M3dE8QFsaGWZK9fuV5 Y4FHowRDZzMV0mWv1dUl9dPraV273oe8fTojWCSMjZ9swji0zTZzpqdA== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:content-type :date:date:from:from:in-reply-to:in-reply-to:message-id :mime-version:references:reply-to:sender:subject:subject:to:to :x-me-proxy:x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s= fm3; bh=vYgKsyC6Ta2sKPoC3Utkwzx7mzKbbTtOTLLZLn4sQvs=; b=f75cd6Ey SXsXX8VXvn74FOPg0opwMHOT1gHTYT1ttWyC38wNV8vPripW8W+g5Ftn2CIzr139 r2Mf3QE4fw7IsHH66AvQAQX/ykwI8HMbQ1myBwN8WkslAKTnjtlSQRZBcpfx8Yu6 pD/BetuicY0rxDoF0JNmOf7glsKT08l1fZ3EwfdiVng4QP1HyIRFbg1k1zvJ5Yij E3wKe1kV3MYOSwVsuUwPOwKhd7b2ceGeLUzIbaOZVzNhPcVXTRBFIzNA3pf11kVL 0m2qPsV87iGNPKEHZXaet9ybSK9Z8Q9tsf4gGUY3NIwmgCxdn1zOkOri88zagLf+ lgrNsPDPEV1vpw== X-ME-Sender: X-ME-Received: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedvvddrudektddgudefiecutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepkfffgggfuffvfhfhjggtgfesth ejredttdefjeenucfhrhhomheptegurhhirghnucfmlhgrvhgvrhcuoegrughrihgrnhdr khhlrghvvghrsegrkhhlrghvvghrrdgtohhmqeenucggtffrrghtthgvrhhnpeffudehtd dugefgkeevudffheevvefhfeettdfhveeivdfgieeghfeiueeggffggeenucffohhmrghi nhepphhoshhtghhrvghsqhhlrdhorhhgnecuvehluhhsthgvrhfuihiivgeptdenucfrrg hrrghmpehmrghilhhfrhhomheprggurhhirghnrdhklhgrvhgvrhesrghklhgrvhgvrhdr tghomh X-ME-Proxy: Received: by mail.messagingengine.com (Postfix) with ESMTPA; Fri, 8 Apr 2022 15:27:44 -0400 (EDT) Message-ID: Date: Fri, 8 Apr 2022 12:27:43 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.7.0 Subject: Re: FOR integer loop bug? Content-Language: en-US To: Ron , pgsql-general@lists.postgresql.org References: <373613a6-7e62-1b03-0010-c0ae55541fd8@gmail.com> From: Adrian Klaver In-Reply-To: <373613a6-7e62-1b03-0010-c0ae55541fd8@gmail.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Archived-At: Precedence: bulk On 4/8/22 11:23, Ron wrote: > On 4/8/22 13:07, Adrian Klaver wrote: >> Hmm, I'm going to have to think on this. > > The only thinking is: "That's a bug waiting to happen!" > That was my first inclination. From here: https://www.postgresql.org/docs/current/plpgsql-control-structures.html#PLPGSQL-CONTROL-STRUCTURES-LOOPS FOR name IN [ REVERSE ] expression .. expression [ BY expression ] LOOP So: CREATE OR REPLACE FUNCTION for_loop_test() RETURNS void LANGUAGE plpgsql AS $function$ BEGIN FOR i IN 1..(2/3.0) LOOP RAISE NOTICE '%', i; END LOOP; END; select for_loop_test(); NOTICE: 1 for_loop_test --------------- Because: select (2/3.0)::int; int4 ------ 1 I find the result from this 1...10 surprising, however I have to believe there is code counting on the equivalent of (2/3.0) working. -- Adrian Klaver adrian.klaver@aklaver.com