X-Original-To: pgsql-performance-postgresql.org@postgresql.org Received: from localhost (wm.hub.org [200.46.204.128]) by postgresql.org (Postfix) with ESMTP id 3CB5A9FB216 for ; Sat, 15 Jul 2006 15:28:17 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.128]) (amavisd-new, port 10024) with ESMTP id 16773-01 for ; Sat, 15 Jul 2006 18:28:13 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey- Received: from moonunit2.moonview.localnet (wsip-70-167-125-69.sd.sd.cox.net [70.167.125.69]) by postgresql.org (Postfix) with ESMTP id 24D5E9FA6AF for ; Sat, 15 Jul 2006 15:28:13 -0300 (ADT) Received: from [192.168.0.3] (moonunit3.moonview.localnet [192.168.0.3]) by moonunit2.moonview.localnet (8.13.1/8.13.1) with ESMTP id k6FIi4MQ010964; Sat, 15 Jul 2006 11:44:04 -0700 Message-ID: <44B92578.1060705@modgraph-usa.com> Date: Sat, 15 Jul 2006 10:27:20 -0700 From: "Craig A. James" User-Agent: Thunderbird 1.5.0.4 (X11/20060516) MIME-Version: 1.0 To: Hassan Adekoya CC: pgsql-performance@postgresql.org Subject: Re: increment Rows in an SQL Result Set postgresql References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/149 X-Sequence-Number: 20009 Hassan, > 1. I have a function that given two parameter produces an arbitrary id, and > text. However arbitrary the id and text are, they are in certain order. i.e. it > is imperative that whatever processing I do, the order is preserved. What type of function is this? Did you write it in C? An SQL procedure? If the function is written in C, you can create a static local variable which you increment every time you call your function, and which you return along with your other two values. As long as your client is connected to the back-end server, you're guaranteed that it's a single process, and it's not multi-threaded, so this is a safe approach. However, note that if you disconnect and reconnect, your counter will be reset to zero. If your function is written in a different language or is a procedure, you might create a sequence that your function can query. The trick is that it is the function itself that must return the incremented value, i.e. you must return three, not two, values from your function. That way, you're not relying on any specific features of the planner, so your three values will stick together. Craig