X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 6981B52868 for ; Thu, 26 May 2005 18:50:39 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 62416-10 for ; Thu, 26 May 2005 21:50:29 +0000 (GMT) Received: from sss.pgh.pa.us (sss.pgh.pa.us [66.207.139.130]) by svr1.postgresql.org (Postfix) with ESMTP id 648F052813 for ; Thu, 26 May 2005 18:50:27 -0300 (ADT) Received: from sss2.sss.pgh.pa.us (tgl@localhost [127.0.0.1]) by sss.pgh.pa.us (8.13.1/8.13.1) with ESMTP id j4QLoT9q008767; Thu, 26 May 2005 17:50:29 -0400 (EDT) To: "gabriele zelasco" Cc: pgsql-general@postgresql.org Subject: Re: Locking rows In-reply-to: <000801c56223$5405a280$f3501897@amdykzpbht0xj0> References: <000801c56223$5405a280$f3501897@amdykzpbht0xj0> Comments: In-reply-to "gabriele zelasco" message dated "Thu, 26 May 2005 20:47:11 +0200" Date: Thu, 26 May 2005 17:50:29 -0400 Message-ID: <8766.1117144229@sss.pgh.pa.us> From: Tom Lane X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.006 tagged_above=0 required=5 tests=AWL X-Spam-Level: X-Archive-Number: 200505/1237 X-Sequence-Number: 78585 "gabriele zelasco" writes: > I would like to start a transaction with a sql function. > When user press "edit" button on my form, i would lock the current row. > After user has modified data on form, pressing "save" button I would save t= > he modified row by sql update function and so commit. This is widely considered a very bad way to design an application. Consider what happens when the user leaves for lunch, or otherwise lets the app sit for a long time. See the list archives for prior discussions of the issue. But in any case, the answer to your question is to use "SELECT FOR UPDATE" to retrieve the row. And you can't start a transaction inside a function, because by definition you'll already be in one. regards, tom lane