pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: gabriele zelasco <rubensoda@inwind.it>
Cc: pgsql-general@postgresql.org
Subject: Re: Locking rows
Date: Thu, 26 May 2005 17:50:29 -0400
Message-ID: <8766.1117144229@sss.pgh.pa.us> (raw)
In-Reply-To: <000801c56223$5405a280$f3501897@amdykzpbht0xj0>
References: <000801c56223$5405a280$f3501897@amdykzpbht0xj0>

"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



view thread (19+ messages)  latest in thread

Message-ID: <8766.1117144229@sss.pgh.pa.us>
Permalink:  ../8766.1117144229@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/8766.1117144229@sss.pgh.pa.us

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-general@postgresql.org
  Cc: tgl@sss.pgh.pa.us, rubensoda@inwind.it
  Subject: Re: Locking rows
  In-Reply-To: <8766.1117144229@sss.pgh.pa.us>
  References: <000801c56223$5405a280$f3501897@amdykzpbht0xj0> <8766.1117144229@sss.pgh.pa.us>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox