From: Hassan <hechy_man@yahoo.com>
To: pgsql-performance@postgresql.org
Subject: Re: increment Rows in an SQL Result Set postgresql
Date: Sat, 15 Jul 2006 11:53:07 -0700 (PDT)
Message-ID: <20060715185307.5589.qmail@web30109.mail.mud.yahoo.com> (raw)
In-Reply-To: <44B92578.1060705@modgraph-usa.com>
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 <cjames@modgraph-usa.com>
To: Hassan Adekoya <hechy_man@yahoo.com>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-performance@postgresql.org
Cc: hechy_man@yahoo.com
Subject: Re: increment Rows in an SQL Result Set postgresql
In-Reply-To: <20060715185307.5589.qmail@web30109.mail.mud.yahoo.com>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox