pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Jan B. <jan@monso.de>
To: Rafa Couto <rafacouto@gmail.com>
Cc: Andrew Hammond <ahammond@ca.afilias.info>
Cc: pgsql-sql@postgresql.org
Subject: Re: Transaction in plpgslq
Date: Tue, 24 May 2005 11:00:36 +0000
Message-ID: <42930954.2090201@monso.de> (raw)
In-Reply-To: <22df564b050524034045f8c174@mail.gmail.com>
References: <22df564b05052003479481da1@mail.gmail.com>
	<428E245B.4050204@ca.afilias.info>
	<22df564b050524034045f8c174@mail.gmail.com>

Rafa Couto wrote:
> 2005/5/20, Andrew Hammond <ahammond@ca.afilias.info>:
> 
> 
>>The solution to your problem is locking (or concurrency control if you
>>prefer). While we're at it, we might as well optimize your statement a
>>little too using ORDER BY with LIMIT instead of min().
>>
>>SELECT id INTO _contacto_id
>>FROM contactos
>>WHERE contactos.operadora_id IS NULL
>>  AND contactos.actividad_id > = _actividad_id
>>ORDER BY id LIMIT 1
>>FOR UPDATE;
>>
>>Take a look at the "FOR UPDATE" section of the SELECT description for an
>>explanation of how this works.
> 
> 
> 
> I understand "FOR UPDATE" clause is locking while is selecting rows
> only. It does not secure atomic execution from 'SELECT' to 'UPDATE' in
> next statement. Is not it?
> 
> 

After the SELECT FOR UPDATE command locked some rows, other concurrent 
changes to the database could be made, but changes, which require to 
lock that rows will be deferred.

The lock will be hold until the end of the transaction (that means at 
least until the function returns).



view thread (6+ messages)  latest in thread

Message-ID: <42930954.2090201@monso.de>
Permalink:  ../42930954.2090201@monso.de/
Also on:    postgresql.org/message-id/42930954.2090201@monso.de

 · 

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 using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: jan@monso.de, rafacouto@gmail.com, ahammond@ca.afilias.info
  Subject: Re: Transaction in plpgslq
  In-Reply-To: <42930954.2090201@monso.de>

* 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