Re: multiple statements.. and locking

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Benjamin <benjamin(at)netyantra(dot)com>
Cc: pgsql-novice(at)postgresql(dot)org
Subject: Re: multiple statements.. and locking
Date: 2004-04-06 04:31:51
Message-ID: 19076.1081225911@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-novice

Benjamin <benjamin(at)netyantra(dot)com> writes:
> I have a C application. I have to modify a row in a table, n then
> immediately access a field in that row.
> These operation of modifying and accessing has to be atomic.So, i have
> to lock the row.

The UPDATE in your example does that already; I think you should just
drop the LOCK ...

> BEGIN; LOCK TABLE tablename in ROW EXCLUSIVE MODE; UPDATE tablename set
> colname=value WHERE rowprimary='a' ; SELECT b from tablename WHERE
> rowprimary='a'; COMMIT;

regards, tom lane

In response to

Browse pgsql-novice by date

  From Date Subject
Next Message Nabil Sayegh 2004-04-06 13:22:56 Re: 7.4 dramatically slower than 7.3? (was: snowflaking)
Previous Message Tom Lane 2004-04-06 04:25:26 Re: Help for MSSQL "Compute" equivalent in Postgres