pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Tom Lane <tgl@sss.pgh.pa.us>
To: Forest Wilkinson <fspam@home.com>
Cc: pgsql-sql@postgresql.org
Cc: pgsql-hackers@postgresql.org
Subject: Re: possible row locking bug in 7.0.3 & 7.1
Date: Wed, 28 Mar 2001 01:11:08 -0500
Message-ID: <17070.985759868@sss.pgh.pa.us> (raw)
In-Reply-To: <01032722080000.08138@bartok>
References: <01032713101600.07241@bartok>
	<15828.985734842@sss.pgh.pa.us>
	<01032722080000.08138@bartok>

Forest Wilkinson <fspam@home.com> writes:
> If I remember correctly, UPDATE establishes a lock on the affected rows, 
> which will block another UPDATE on the same rows for the duration of the 
> transaction.  If that's true, shouldn't I be able to achieve my desired 
> behavior by removing the initial as follows:

> create function nextid( varchar(32)) returns int8 as '
>   update idseq set id = id + 1 where name = $1::text;
>   select id from idseq where name = $1::text;
>   ' language 'sql';

> Or, would I still have to add FOR UPDATE to that final SELECT?

You're right, the initial SELECT FOR UPDATE is a waste of cycles
considering that you're not using the value it returns.  But you'll
still need the last select to be FOR UPDATE so that it plays by the
same rules as the UPDATE does.

			regards, tom lane



view thread (21+ messages)  latest in thread

Message-ID: <17070.985759868@sss.pgh.pa.us>
Permalink:  ../17070.985759868@sss.pgh.pa.us/
Also on:    postgresql.org/message-id/17070.985759868@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-sql@postgresql.org
  Cc: tgl@sss.pgh.pa.us, fspam@home.com, pgsql-hackers@postgresql.org
  Subject: Re: possible row locking bug in 7.0.3 & 7.1
  In-Reply-To: <17070.985759868@sss.pgh.pa.us>
  References: <01032713101600.07241@bartok> <15828.985734842@sss.pgh.pa.us> <01032722080000.08138@bartok> <17070.985759868@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