Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id 0DC2C475E6F; Mon, 16 Dec 2002 11:23:32 -0500 (EST) Received: from localhost.localdomain (unknown [65.217.53.66]) by postgresql.org (Postfix) with ESMTP id 8DCF3475E60; Mon, 16 Dec 2002 11:23:29 -0500 (EST) Received: from thorn.mmrd.com (thorn.mmrd.com [172.25.10.100]) by localhost.localdomain (8.12.5/8.12.5) with ESMTP id gBGGZC6P026469; Mon, 16 Dec 2002 11:35:12 -0500 Received: from gnvex001.mmrd.com (gnvex001.mmrd.com [192.168.3.55]) by thorn.mmrd.com (8.11.6/8.11.6) with ESMTP id gBGGNXj19370; Mon, 16 Dec 2002 11:23:33 -0500 Received: from camel.mmrd.com ([172.25.5.213]) by gnvex001.mmrd.com with SMTP (Microsoft Exchange Internet Mail Service Version 5.5.2653.13) id XX5JXTYH; Mon, 16 Dec 2002 11:23:33 -0500 Subject: working around setQuerySnapshot limitations in functions From: Robert Treat To: pgsql-sql@postgresql.org Cc: "pgsql-general@postgresql.org" Content-Type: text/plain Content-Transfer-Encoding: 7bit X-Mailer: Ximian Evolution 1.0.8 Date: 16 Dec 2002 11:23:33 -0500 Message-Id: <1040055813.19398.49.camel@camel> Mime-Version: 1.0 X-Virus-Scanned: by AMaViS new-20020517 X-Archive-Number: 200212/760 X-Sequence-Number: 34675 I have a function called move_tree() which moves a node from 1 parent to another (in a nested set tree) by computing some necessary values, then updating the nodes as needed. The problem I have is that when the function is called multiple times simultaneously, each function does a setQuerySnapshot at the start of the function, and then cannot see the changes made by the other function calls. I had thought to do a lock on the table at the start of my function, but due to the fact setQuerySnapshot is called at the function start (before I can acquire a lock) I can't guarantee no changes have been made before the function tries to make changes. ISTM the only way around this is to do a lock on the table before calling the function. The major downside to that it requires me to put that logic inside any apps that use the function, rather than being able to keep it inside the database. Does anyone see another work-around? Robert Treat