Re: Locking rows

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: "gabriele zelasco" <rubensoda(at)inwind(dot)it>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Locking rows
Date: 2005-05-26 21:50:29
Message-ID: 8766.1117144229@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

"gabriele zelasco" <rubensoda(at)inwind(dot)it> 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

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2005-05-26 22:00:33 Re: another failover testing question
Previous Message David Fetter 2005-05-26 21:48:41 Re: Just a crazy idea!