Re: Convert Cursor to array

From: "FERREIRA William (COFRAMI)" <william(dot)ferreira(at)airbus(dot)com>
To: 'Richard Huxton' <dev(at)archonet(dot)com>, "GIROIRE Nicolas (COFRAMI)" <nicolas(dot)giroire(at)airbus(dot)com>
Cc: "'pgsql-general(at)postgresql(dot)org'" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Convert Cursor to array
Date: 2005-03-15 09:02:03
Message-ID: 1904E3EB39448246A7ECB76DF34A70B00143B485@TOCOMEXC03
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

ok, i think that i will try to use pl/perl or pl/python
but i don't know which one is better for my problem

maybe you can help me.
thanks

-----Message d'origine-----
De : pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org]De la part de Richard Huxton
Envoyé : lundi 14 mars 2005 09:31
À : GIROIRE Nicolas (COFRAMI)
Cc : 'pgsql-general(at)postgresql(dot)org'
Objet : Re: [GENERAL] Convert Cursor to array

GIROIRE Nicolas (COFRAMI) wrote:
> my sort algorithm is a very particular solution.
> In fact, I put record in array to allow me to sort record. I sort them by
> using one column of my table but the column indx can have duplicate value
> and it's volontary.

I still can't see why you can't sort by that column with "order by"
There's nothing obvious in your description that rules that out. Are you
aware that PostgreSQL offers functional and partial indexes? They can
make complex selection/ordering quite efficient.

> here is the order algorithm :
> for i in 1..recordcount loop
> tmp_row := children[i];
> indx := tmp_row[5];
>
> if (indx<i) then
> -- on déplace les éléments pour laisser la
> place à l'élément qu'on déplace
> for j in 0..(i-indx-1) loop
> children[i-j] := children[i-j-1];
> end loop;
> -- on met l'élément à sa nouvelle position
> children[indx] := tmp_row;
> end if;
> end loop;
>
> It's particular to my system. I won't go to explain my choice but if
someone
> has an idea to save time.

If you are going to sort, this looks a particularly slow algorithm for
large values of "recordcount". Personally, I'd use plperl/plpython or
something with built-in hash sorting capabilities. That will almost
certainly be tens or hundreds of times faster.

--
Richard Huxton
Archonet Ltd

---------------------------(end of broadcast)---------------------------
TIP 2: you can get off all lists at once with the unregister command
(send "unregister YourEmailAddressHere" to majordomo(at)postgresql(dot)org)

This mail has originated outside your organization,
either from an external partner or the Global Internet.
Keep this in mind if you answer this message.

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sim Zacks 2005-03-15 09:38:48 Re: plpython function problem workaround
Previous Message Sim Zacks 2005-03-15 08:40:00 Re: plpython function problem workaround