Received: from localhost (unknown [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id F1C842E0302 for ; Wed, 28 Nov 2007 00:46:41 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 47601-04 for ; Wed, 28 Nov 2007 00:46:29 -0400 (AST) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 090CD2E1D81 for ; Wed, 28 Nov 2007 00:46:29 -0400 (AST) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.1/8.14.1) with ESMTP id lAS4kTA4018954; Tue, 27 Nov 2007 23:46:29 -0500 (EST) To: "Daniel Caune" cc: pgsql-sql@postgresql.org Subject: Re: Strang behaviour SELECT ... LIMIT n FOR UPDATE In-reply-to: <1E293D3FF63A3740B10AD5AAD88535D2068A6247@UBIMAIL1.ubisoft.org> References: <1E293D3FF63A3740B10AD5AAD88535D2068A6247@UBIMAIL1.ubisoft.org> Comments: In-reply-to "Daniel Caune" message dated "Tue, 27 Nov 2007 19:16:17 -0500" Date: Tue, 27 Nov 2007 23:46:29 -0500 Message-ID: <18953.1196225189@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200711/140 X-Sequence-Number: 29668 "Daniel Caune" writes: > I'm facing a strange behaviour with a statement SELECT ... LIMIT n FOR > UPDATE in PostgreSQL 8.1. The number of rows returned is actually (n - > 1). I'm trying to find whether this is an identified issue with > PostgreSQL 8.1 that might have been fixed in a later version such as > 8.2; I don't have any problem in moving to a later version if needed. There's no known issue specifically of that form (and a quick test of 8.1 doesn't reproduce any such behavior). However, it is known and documented that LIMIT and FOR UPDATE behave rather oddly together: the LIMIT is applied first, which means that if FOR UPDATE rejects any rows as being no longer up-to-date, you get fewer than the expected number of rows out. You did not mention any concurrent activity in your example, but I'm betting there was some ... regards, tom lane