Received: from localhost (maia-5.hub.org [200.46.204.182]) by postgresql.org (Postfix) with ESMTP id BE8BE9F965C for ; Mon, 20 Aug 2007 15:03:15 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.182]) (amavisd-maia, port 10024) with ESMTP id 85942-07 for ; Mon, 20 Aug 2007 15:03:10 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.5 Received: from rv-out-0910.google.com (rv-out-0910.google.com [209.85.198.184]) by postgresql.org (Postfix) with ESMTP id E85AF9F9661 for ; Mon, 20 Aug 2007 15:03:11 -0300 (ADT) Received: by rv-out-0910.google.com with SMTP id l15so984443rvb for ; Mon, 20 Aug 2007 11:03:10 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=sEZj2IuEtHbI0UpNi8Mhd1grXNpBnzmnTd/vW6NHcfbXR7wHTF/+DhRC45gGVdBvKkl1dQerrmV62keN8lc4aPCPuTixN69yYl5ejNQqYYSPkq/pj9sNzIQl9tiNMe+D5iwjv5jxw+fUe+9Kz2Hd9FFY4Y1LrRXEzxJz5t9T790= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=tJ1XfMxWQMHzAP1gbjBu9RfrLWT9Sxgnbr1hYUsmm2zmGJuSbLSotTTwX410ucrBG0VO5M7FxjN75arkmUjdiyK/2vLCiEleTq5pGQlyOHdT9nUh5uZt/gmxQ2I+llFKZYYpSoBefGBmkm07cePo7bKKWcRLFD59Rjk6/T0bQTE= Received: by 10.141.170.10 with SMTP id x10mr2865445rvo.1187632990649; Mon, 20 Aug 2007 11:03:10 -0700 (PDT) Received: by 10.141.98.12 with HTTP; Mon, 20 Aug 2007 11:03:10 -0700 (PDT) Message-ID: Date: Mon, 20 Aug 2007 13:03:10 -0500 From: "Scott Marlowe" To: "Medi Montaseri" Subject: Re: how to call sql code without function Cc: giuseppe.derossi@email.it, pgsql-admin@postgresql.org In-Reply-To: <8078a1730708201029o744efd76yb96c5e4c2cac54fe@mail.gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <982e37715bf2f368a09ab98ac244a032@83.225.20.212> <8078a1730708201029o744efd76yb96c5e4c2cac54fe@mail.gmail.com> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200708/229 X-Sequence-Number: 26560 On 8/20/07, Medi Montaseri wrote: > You can think of a database as a filesystem as well. That is do some > processing, store the result in temp table, do some more, etc,etc then merge > and process temp tables to arrive at some result. > > Just as in the case of filesystem, if you are operating in a concurrent > evironment, you need to fence against that. That is it is possible that at a > given time two sessions will arrive at the same processing point where they > need to create such temp tables. Each session will get it's own temp table, even if they have the same name. The real issue is what they do with the data in that temp table to make sure that they're committing changes that make sense given the current state of data in the database. > The other solution which I prefer is to write a stored procedure to solve > this. Or get creative with nested and complex SQL queries. Note that nested queries still have some race conditions (such as with aggregate functions) in postgresql.