Received: from magus.postgresql.org (magus.postgresql.org [87.238.57.229]) by mail.postgresql.org (Postfix) with ESMTP id 45DD873FD6E for ; Sat, 9 Jun 2012 21:11:07 -0300 (ADT) Received: from smtp109.prem.mail.ac4.yahoo.com ([76.13.13.92]) by magus.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1SdVkG-0005dE-2q for pgsql-general@postgresql.org; Sun, 10 Jun 2012 00:11:06 +0000 Received: (qmail 87333 invoked from network); 10 Jun 2012 00:10:50 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=DKIM-Signature:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=krkKRoiJva6ZCjOfdf/E9AZYTijalTgYKcXa1dgpK4pEK0rBsTOG05DmlbmDFQyU+8Y73rGvzwcO8zQR/NfZ7SgiltY5UgVMOp6EnK1Rr7C+27CnV2h9z8FaEHOoHJTndgwa+99iAUyNiyiFOs4tL3tA0Q78o5/B6HiB2+rPd24= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1339287050; bh=aBpWPY7n2rftCf26P3vV7o/xZOZ9XX4qixpvmsLkMBU=; h=X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:References:In-Reply-To:Subject:Date:Message-ID:MIME-Version:Content-Type:Content-Transfer-Encoding:X-Mailer:Thread-Index:Content-Language; b=KbCoRlaN68WgoOCRRXJsrGRMglakAaHopnOg+6N87XoVjm5Jl755xbkMjmuNipbBj6IJ6XqW5Lm/smDhcDlLiPZj5UDuNnKs3t3gKzOYkcaaK72r6bbsdcp7sf6IN3Gy3kd4CQnMlQMk1iJEHQ8EfHQJ1CVvf/a/vtb2vT6Yv7w= X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: LrZOJRYVM1mKri_KzmaPzkS4qiXGgjXCA2tAmXrDriJxhoP 4RFHwFu_d.5iWrx5YPx44ZSsK3ZpYQgd2fbmvJfrD6dKThzvFaUTZMUvXJN0 7FKHv6hx6wD4_gu5whQJpRX.lkZ8qvc1F3WzW7sKEyZarrVjrApNzhGizBHA OZSf_vAGeC9FNsvfcOk1KBgO5T.PJaRlY9El5ldQBTgGZEYSxPIY._d6EfOX UqS5pSrnT8kjn.bo52qaoZ.WWBqno9iMCZ97GeXUpg8iwtGeunFha7SV2KCD rMSYJ70Eq.e3x0gxyhQ..08WT3No67d.ar_Z3qaeYI5U5jSCf770.rcmmUQv srFDxc6kYDS8pMXBGlJC98qZncQWx1L9egnG50YNUUjTzoH1MSHr6r21.ojI 5O0c8uH_fukz20NFC8KWX X-Yahoo-SMTP: mpGJl6eswBD2IBufoVEg0Pa8gg-- Received: from WolfDog (polobo@24.93.23.188 with login) by smtp109.prem.mail.ac4.yahoo.com with SMTP; 09 Jun 2012 17:10:50 -0700 PDT From: "David Johnston" To: "'Evan Rempel'" , References: <4F8B6AA1.1040709@zvelo.com> <20120416065717.70a31a6361ac5d7bdad416e8@frank.uvena.de> <4F8BD91C.6070405@zvelo.com> <4F8BDAB2.7010209@frank.uvena.de> <4F8C248E.7070307@zvelo.com> <4F8CC11A.5020003@d2.com> <4F8CDB95.3040407@zvelo.com> <4F8E04D9.6010402@zvelo.com> , <20120531093728.GA25109@depesz.com> In-Reply-To: Subject: Re: is there a select for update insert if not exist type command? Date: Sat, 9 Jun 2012 20:10:38 -0400 Message-ID: <001a01cd469d$791b6260$6b522720$@yahoo.com> MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit X-Mailer: Microsoft Outlook 14.0 Thread-Index: AQEPw5tNIB+Ua5xMABLnyHgAr6EY7wGxDrknAbD5Sl4BynBR2wIE75v4AUbzAk4BRrC+6QNcpL4rATHyCXkCExH5LgJvOYWYAW2IMFCXy8VH0A== Content-Language: en-us X-Pg-Spam-Score: -2.0 (--) X-Archive-Number: 201206/189 X-Sequence-Number: 187969 > -----Original Message----- > > Both clients A and B becomes aware to do a task > Ideally you would have this aware-ness manifested as an INSERT into some kind of job table. The clients can issue the "SELECT FOR UPDATE" + "UPDATE" commands to indicate that they are going to be responsible for said task. You seem to combining "something needs to be done" with "I am able to do that something". You may not have a choice depending on your situation but it is something to think about - how can I just focus on implementing the "something needs to be done" part. If you want to avoid the errors appearing in the logs or client you could just wrap the INSERT command into a function and trap the duplicate key exception. It is hard to give suggestions when you are as vague as "becomes aware to do a task". Ideally even if you have multiple clients monitoring for "aware state" only one client should ever actually realize said awareness for a given task. In effect you want to serialize the monitoring routine at this level, insert the "something needs to be done" record, then serialize (for update) the "I am able to do that something" action. David J.