Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id BB7529FA3C0 for ; Fri, 6 Oct 2006 13:25:29 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 28454-04 for ; Fri, 6 Oct 2006 16:25:24 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by postgresql.org (Postfix) with ESMTP id 69D1A9FA0C4 for ; Fri, 6 Oct 2006 13:25:24 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.6/8.13.6) with ESMTP id k96GPNnd021635; Fri, 6 Oct 2006 12:25:23 -0400 (EDT) To: James Robinson cc: pgsql-sql@postgresql.org Subject: Re: SELECT FOR UPDATE/SHARE cannot be applied to the nullable side of an outer join In-reply-to: References: Comments: In-reply-to James Robinson message dated "Fri, 06 Oct 2006 11:31:47 -0400" Date: Fri, 06 Oct 2006 12:25:23 -0400 Message-ID: <21634.1160151923@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200610/81 X-Sequence-Number: 26470 James Robinson writes: > select a.id, b.id from foo a left outer join bar b on (b.a_id = > a.id) for update; > SELECT FOR UPDATE/SHARE cannot be applied to the nullable side of an > outer join > Is this behavior spec-mandated, or could only the rows in B which are > not-null be locked? I don't believe that the spec expects FOR UPDATE to work on outer joins. The problem with it is what does it mean to lock the result of a select from an outer join? To my mind, a lock on a select result means that you've guaranteed that no one else can change the rows you selected. In an outer join it's impossible to guarantee that --- someone could insert a B row that matches a formerly unmatched A row. If you now re-did the SELECT you would get a different result, ie, your null-extended A row would be replaced by a normal row, even though you had lock on that A row. (This does not speak to the question of new rows showing up in the second SELECT --- that's always possible. The point is that a row you got the first time is now different despite being "locked".) So I tend to feel that if you think you need this, you need to rethink your data model. Note that you can select "FOR UPDATE OF a" in this situation, it's just the B side that is problematic. regards, tom lane