From: | "Jason" <jason(dot)leach(at)gmail(dot)com> |
---|---|
To: | pgsql-general(at)postgresql(dot)org |
Subject: | My Slow query. |
Date: | 2005-08-24 18:38:26 |
Message-ID: | 1124908706.737661.9060@o13g2000cwo.googlegroups.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Hi:
I have a query that uses one table with about 1 million rows. So far it
has been running for about 12h on a P4 3Ghz. The query/function does
this:
Esentially flattens some data. It looks through the values in a row,
does an if/else to categorize the value and update another table based
on the if/else. I put it into a function. The function is at the end
of this msg.
So I have a talble that looks like:
SPECIES_ORDER speciecCode speciesPercent
1 PL 10
1 P 30
2 Sp 11
And I turn it into
speciesCode1 speciesPercent1 speciesCode2 speciesPercent2
PL 10 Sp 11
P Sp NULL NULL
So the 1,2.. in the colum names comes from the ORDER_NUMBER.
I might be able to use the contributed crosstab function. Any ideas or
comments?
Thanks,
Jason.
DECLARE
r RECORD;
BEGIN
FOR r IN SELECT * FROM RDD010 LOOP
IF r."SPECIES_ORDER" = 1 THEN
UPDATE public.RES_layers
Set "speciesCode1" = r."speciesCode", "speciesPercent1" =
r."speciesPercent"
where public.RES_layers."FOREST_COVER_LAYER_ID" =
r."FOREST_COVER_LAYER_ID";
ELSIF r."SPECIES_ORDER" = 2 THEN
UPDATE public.RES_layers
Set "speciesCode2" = r."speciesCode", "speciesPercent2" =
r."speciesPercent",
"averageAge_spp2" = r."averageAge", "averageHeight_spp2" =
r."averageHeight"
where public.RES_layers."FOREST_COVER_LAYER_ID" =
r."FOREST_COVER_LAYER_ID";
ELSIF r."SPECIES_ORDER" = 3 THEN
UPDATE public.RES_layers
Set "speciesCode3" = r."speciesCode", "speciesPercent3" =
r."speciesPercent"
where public.RES_layers."FOREST_COVER_LAYER_ID" =
r."FOREST_COVER_LAYER_ID";
ELSIF r."SPECIES_ORDER" = 4 THEN
UPDATE public.RES_layers
Set "speciesCode4" = r."speciesCode", "speciesPercent4" =
r."speciesPercent"
where public.RES_layers."FOREST_COVER_LAYER_ID" =
r."FOREST_COVER_LAYER_ID";
ELSIF r."SPECIES_ORDER" = 5 THEN
UPDATE public.RES_layers
Set "speciesCode5" = r."speciesCode", "speciesPercent5" =
r."speciesPercent"
where public.RES_layers."FOREST_COVER_LAYER_ID" =
r."FOREST_COVER_LAYER_ID";
END IF;
END LOOP;
RETURN 0;
end;
From | Date | Subject | |
---|---|---|---|
Next Message | Dann Corbit | 2005-08-24 18:59:59 | Re: My Slow query. |
Previous Message | Welty, Richard | 2005-08-24 18:36:52 | Re: Postgresql replication |