Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VK852-0007QK-EO for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Sep 2013 14:41:12 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1VK851-0007Xe-TQ for pgsql-bugs@arkaria.postgresql.org; Thu, 12 Sep 2013 14:41:11 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VK851-0007XY-9S for pgsql-bugs@postgresql.org; Thu, 12 Sep 2013 14:41:11 +0000 Received: from mahout.postgresql.org ([2001:4800:7903:4::123]) by magus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VK84y-0001Hg-1L for pgsql-bugs@postgresql.org; Thu, 12 Sep 2013 14:41:10 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1VK84w-0001nF-D5 for pgsql-bugs@postgresql.org; Thu, 12 Sep 2013 14:41:07 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.80) (envelope-from ) id 1VK84r-0004zz-33 for pgsql-bugs@postgresql.org; Thu, 12 Sep 2013 14:41:01 +0000 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Subject: BUG #8448: looping through query results exits at 10th step under some conditions To: pgsql-bugs@postgresql.org From: laszlo.rozsahegyi@rool.hu Message-Id: Date: Thu, 12 Sep 2013 14:41:01 +0000 X-Pg-Spam-Score: -2.8 (--) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The following bug has been logged on the website: Bug reference: 8448 Logged by: László Rózsahegyi Email address: laszlo.rozsahegyi@rool.hu PostgreSQL version: 9.3.0 Operating system: windows 7 64 bit Description: Looping through query results exits at 10th step when * query has for update clause, and * in loop body between 1 and 10 step update - at least one step - the locked record I tested it after a fresh and clean PostgreSQL install. The configuration files left unchanged. test code (bur_report.sql): set client_encoding='UTF-8'; /* looping through query results exits at 10th step under some conditions */ create database looptest; \c looptest create sequence id_seq start 100; create table test ( id bigint not null unique default nextval('id_seq') , code varchar(3) not null , note text ); insert into test (code) values ('HUN'), ('ENG'); create type t_10 as ( num integer , note text ); select n.id, g.i from test n , generate_series(1,15) g(i) where n.code = 'HUN' order by 2 ; /* The results are 15 rows */ create or replace function update10() returns setof t_10 language plpgsql volatile security definer as $BODY$ declare lRec record; lSor t_10; begin for lRec in select n.id, g.i from test n , generate_series(1,15) g(i) /* 15 > 10 */ where n.code = 'HUN' order by 2 for update of n /* bug part 1 */ loop lSor.num = lRec.i; lSor.note = lRec.id::text || '-' || lRec.i::text; /* exit loop after 10th step when update locked record in 1..10 step otherwise returns all 15 record (example condition is lRec.i > 10 ) */ if lRec.i = 1 then update test set note = lSor.note where id = lRec.id; /* bug part 2 */ end if; return next lSor; end loop; return; end; $BODY$ ; select * from update10(); /* The results are 10 records */ \c postgres drop database looptest; -- end code The last query results are 10 records. I expected 15 records, like the other query. I tested the code in windows 7 command prompt: C:\temp>"c:\Program Files\PostgreSQL\9.3\bin\psql.exe" -Upostgres -h127.0.0.1 -p5557 -f bug_report.sql Password for user postgres: SET CREATE DATABASE You are now connected to database "looptest" as user "postgres". CREATE SEQUENCE CREATE TABLE INSERT 0 2 CREATE TYPE id | i -----+---- 100 | 1 100 | 2 100 | 3 100 | 4 100 | 5 100 | 6 100 | 7 100 | 8 100 | 9 100 | 10 100 | 11 100 | 12 100 | 13 100 | 14 100 | 15 (15 rows) CREATE FUNCTION num | note -----+-------- 1 | 100-1 2 | 100-2 3 | 100-3 4 | 100-4 5 | 100-5 6 | 100-6 7 | 100-7 8 | 100-8 9 | 100-9 10 | 100-10 (10 rows) You are now connected to database "postgres" as user "postgres". DROP DATABASE C:\temp> -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs