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 AC67E9FB216 for ; Sat, 15 Jul 2006 15:53: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 47140-03 for ; Sat, 15 Jul 2006 18:53:09 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey- Received: from web30109.mail.mud.yahoo.com (web30109.mail.mud.yahoo.com [68.142.200.82]) by postgresql.org (Postfix) with SMTP id E0A659FA666 for ; Sat, 15 Jul 2006 15:53:08 -0300 (ADT) Received: (qmail 5591 invoked by uid 60001); 15 Jul 2006 18:53:07 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.com; h=Message-ID:Received:Date:From:Reply-To:Subject:To:In-Reply-To:MIME-Version:Content-Type; b=g9ajFKmWTxw042LjUEgWx3mszl+X2TTFMJgRvstMEzZ4TZ3jSjaTKwwD7J0bnWQ1zVF8yrGdf7BNbrSI5B8uUcU9fyEFUtoFObIFW17dNMRWN2O6Y+s78KoG820RwL5gKFaZ4YcUxsmsjAw5um5jWvtip965qjdTsKgd8hhxe7k= ; Message-ID: <20060715185307.5589.qmail@web30109.mail.mud.yahoo.com> Received: from [63.13.248.139] by web30109.mail.mud.yahoo.com via HTTP; Sat, 15 Jul 2006 11:53:07 PDT Date: Sat, 15 Jul 2006 11:53:07 -0700 (PDT) From: Hassan Reply-To: Hassan Subject: Re: increment Rows in an SQL Result Set postgresql To: pgsql-performance@postgresql.org In-Reply-To: <44B92578.1060705@modgraph-usa.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200607/150 X-Sequence-Number: 20010 Sadly I didnt write this function. It was written in C and packaged in a shared module .so. I access it thru postgresql as plpgsql function. I cannot edit the function thus. I tried this CREATE TEMPORARY SEQUENCE serial START 1; SELECT nextval('serial'), astext(tmp.the_geom), street FROM shortest_path_as_geometry('bklion', 185, 10953) AS tmp LEFT JOIN (SELECT * FROM bklion) AS ss ON ss.the_geom = tmp.the_geom; I know this is inefficient, and I surely dont know the repercussion of using the temporary sequence in a web application. Do you? Appreciate any input. Thanks! - Hassan Adekoya ----- Original Message ---- From: Craig A. James To: Hassan Adekoya Cc: pgsql-performance@postgresql.org Sent: Saturday, July 15, 2006 1:27:20 PM Subject: Re: [PERFORM] increment Rows in an SQL Result Set postgresql 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