plpgsql and for with integer loopvar error - Mailing list pgsql-sql

From Ari Kahn
Subject plpgsql and for with integer loopvar error
Date
Msg-id BDCD90E6-6770-11D9-97FB-000D936D7BC4@gmu.edu
Whole thread Raw
Responses Re: plpgsql and for with integer loopvar error
List pgsql-sql
I have a single column result that I want to loop through using an 
index. I also want to jump ahead in the result using the index (below: 
i:=i+cluster_cnt-1;) . However, I'm getting the following error.

ERROR:  syntax error at or near "SELECT" at character 9
CONTEXT:  PL/pgSQL function "gets_nooky" line 14 at for with integer 
loopvar

Here is my function ...

CREATE FUNCTION gets_nooky() returns numeric AS
'
DECLARE    i integer;    gt1cnt record;    gt1 record;    cluster record;    cluster_cnt integer;    slocus integer;
minmaxrecord;
 

BEGIN    SELECT INTO gt1 * FROM cgt1;    SELECT count(*) INTO gt1cnt FROM cgt1;
    FOR i IN 1 .. SELECT count(*) FROM cgt1    LOOP
        SELECT INTO cluster DISTINCT qry        FROM seeds2        WHERE seed IN (            SELECT qry
FROMseeds2            WHERE seed=gt1.seed[i]);
 
        slocus := i;
        SELECT INTO minmax min(qle) AS mqle, max(que) AS mque        FROM seeds2        WHERE seed IN (SELECT * FROM
cluster);
        UPDATE locus        SET locus=slocus, lle=minmax.mqle, lue=minmax.mque        WHERE id IN (            SELECT *
          FROM cluster            );
 
        SELECT INTO cluster_cnt count(*) FROM cluster;        i:=i+cluster_cnt-1;        DELETE FROM cluster;
    END LOOP;
    return i;

END;
'
language 'plpgsql';


Any help is much appreciated!

Thanks,
Ari



pgsql-sql by date:

Previous
From: Richard Huxton
Date:
Subject: Re: Inserting or Deleting conditionally
Next
From: "Yudie"
Date:
Subject: query configuration for validate empty quote to zero