X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id 83046528A9 for ; Tue, 24 May 2005 07:40:57 -0300 (ADT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 90552-07 for ; Tue, 24 May 2005 10:40:55 +0000 (GMT) Received: from rproxy.gmail.com (rproxy.gmail.com [64.233.170.198]) by svr1.postgresql.org (Postfix) with ESMTP id 03940528D0 for ; Tue, 24 May 2005 07:40:52 -0300 (ADT) Received: by rproxy.gmail.com with SMTP id i8so928816rne for ; Tue, 24 May 2005 03:40:55 -0700 (PDT) DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=beta; d=gmail.com; h=received:message-id:date:from:reply-to:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=ebGrzheZdwKH0axEfmy+tjwv2xXftAxVubTHoE9wXYSe9DuomtwvtjXlr24XgM3C2VpmcsxV6tDI2fu5KEtCX8PHjXWmF6765XchAVR/tcOxkz/LJrGJtcxVm0OhPY+RgoL0iKppV+2l7I3sUqT1Ag3L7fbNN/6/9wDuOpUf1YU= Received: by 10.38.78.22 with SMTP id a22mr327446rnb; Tue, 24 May 2005 03:40:55 -0700 (PDT) Received: by 10.38.79.24 with HTTP; Tue, 24 May 2005 03:40:55 -0700 (PDT) Message-ID: <22df564b050524034045f8c174@mail.gmail.com> Date: Tue, 24 May 2005 12:40:55 +0200 From: Rafa Couto Reply-To: Rafa Couto To: Andrew Hammond Subject: Re: Transaction in plpgslq Cc: pgsql-sql@postgresql.org In-Reply-To: <428E245B.4050204@ca.afilias.info> Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Content-Disposition: inline References: <22df564b05052003479481da1@mail.gmail.com> <428E245B.4050204@ca.afilias.info> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.597 tagged_above=0 required=5 tests=AWL, DNS_FROM_RFC_ABUSE, INFO_TLD, RCVD_BY_IP X-Spam-Level: X-Archive-Number: 200505/199 X-Sequence-Number: 21512 2005/5/20, Andrew Hammond : > 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(). >=20 > SELECT id INTO _contacto_id > FROM contactos > WHERE contactos.operadora_id IS NULL > AND contactos.actividad_id > =3D _actividad_id > ORDER BY id LIMIT 1 > FOR UPDATE; >=20 > 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? --=20 Rafa Couto (caligari)