RE: [GENERAL] How to do this in Postgres

From: Fabian(dot)Frederick(at)prov-liege(dot)be
To: holger(at)klawitter(dot)de, pgsql-general(at)postgreSQL(dot)org
Cc: didier(at)sonycom(dot)com, christophe(dot)gavage(at)nrb(dot)be, philippe(dot)frederick(at)Beldi(dot)be, dutshs(at)yahoo(dot)com, franckenj(at)hotmail(dot)com, frederic(dot)langer(at)groupes(dot)be, jean(dot)francois(dot)lefebvre(at)comexis(dot)com, Freddy(dot)Frederick(at)readymix(dot)be, REMACLT1(at)midas-kapiti(dot)com
Subject: RE: [GENERAL] How to do this in Postgres
Date: 1999-11-23 14:12:10
Message-ID: 17AB709C82E5D111ACF20000F805F4532B4040@mesadm.epl.prov-liege.be
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> Hi there,
>
> I tried all I could think of with the following problem, perhaps
> someone has another idea.
>
> I have a table where for each id there may (and often are) multiple
> rows with some kind of priority.
> create table data ( id1 int4, id2 int4, <<lots of data>>,
> prio int4 );
> The minimal priority is not guaranteed to be 1. There are 200k
> different ids with up to 10 entries, summing up to 400k rows.
>
> Not I want to do something like this:
>
> select * from data where <<prio is minimal per id pair>>.
>
> First attempt (deleting non minimal)
> ------------------------------------
>
> select a.id1, a.id2, a.prio
> into bugos
> from a data, b data
> where a.prio > b.prio and a.id1 = b.id1 and a.id2 = b.id2;
>
> delete from data
> where id1 = bogus.id1 and id2 = bogus.id2 and prio = bogus.prio;
>
> The join does not seem to complete. I am not sure whether I should
> have waited longer, but after 4h without significant disk access I
> do not think that this thing will ever return. Indexing didn't help.
>
> Second attempt (stored procedures)
> ----------------------------------
>
> create function GetData( int4, int4 )
> returns data
> as 'select *
> from data
> where id1 = $1 and id2 = $2
> order by prio
> limit 1'
> language 'sql';
>
> select GetData(id1,id2) from <<table with unique ids>>;
>
> limit in functions is not yet implemented in postgres (6.5.2)
>
> Third attempt (use perl on dumped table)
> ----------------------------------------
>
> I don't want to :-)

IMHO, Perl is the solution,
some foreach architecture on @table should work...
Of course it could be ordinal (usable on fixed row system).
The best would be to recover row name as well(if someone has an
idea to do this ???):

foreach $item in fetched_row{
#Recover row name (Process runned once (rec#1)
???
#Recover row content
}

Regards, Fabian

Responses

Browse pgsql-general by date

  From Date Subject
Next Message fk 1999-11-23 14:55:05 Tcl from a Web-browser
Previous Message Alain.Tesio 1999-11-23 12:34:39 Re: [GENERAL] How to do this in Postgres