Re: Locking rows - Mailing list pgsql-general

From Tom Lane
Subject Re: Locking rows
Date
Msg-id 8766.1117144229@sss.pgh.pa.us
Whole thread Raw
In response to Locking rows  ("gabriele zelasco" <rubensoda@inwind.it>)
List pgsql-general
"gabriele zelasco" <rubensoda@inwind.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

pgsql-general by date:

Previous
From: David Fetter
Date:
Subject: Re: Just a crazy idea!
Next
From: Tom Lane
Date:
Subject: Re: another failover testing question