From: | "Oleg Lebedev" <oleg(dot)lebedev(at)waterford(dot)org> |
---|---|
To: | "Zac Hillier" <zac(at)affectors(dot)net>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: foreach in sql functions |
Date: | 2002-10-02 22:24:41 |
Message-ID: | 993DBE5B4D02194382EC8DF8554A5273016DB6@postoffice.waterford.org |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Try something along the following lines:
DROP FUNCTION crt_bsk_dtl (INTEGER);
CREATE FUNCTION crt_bsk_dtl (INTEGER) RETURNS INTEGER AS '
DECLARE curs CURSOR FOR
SELECT PrdKey FROM Prd WHERE Sts < 999;
DECLARE
rec RECORD;
BEGIN
OPEN curs;
LOOP
-- fetch next record
FETCH curs INTO rec;
EXIT WHEN NOT FOUND;
INSERT INTO BskDtl (BskKey, PrdKey) VALUES ($1,
rec.PrdKey);
END LOOP;
CLOSE curs;
RETURN 1;
END;
' language 'plpgsql';
-----Original Message-----
From: Zac Hillier [mailto:zac(at)affectors(dot)net]
Sent: Wednesday, October 02, 2002 4:16 PM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] foreach in sql functions
Hi All,
I have only recently started using pgsql and would like to try some
internal functions as it appears this would be quicker than running
similar functions from php.
Is it possible to write sql functions with a foreach style loop?
CREATE FUNCTION crt_bsk_dtl(integer) RETURNS integer AS '
SELECT PrdKey FROM Prd WHERE Sts < 999;
foreach(Prd.PrdKey){
INSERT INTO BskDtl (BskKey, PrdKey) VALUES ($1, Prd.PrdKey);
}
SELECT 1;
' LANGUAGE SQL
Any help or pointers very much appreciated.
Thanks
Zac
---------------------------(end of broadcast)---------------------------
TIP 6: Have you searched our list archives?
From | Date | Subject | |
---|---|---|---|
Next Message | Neil Conway | 2002-10-02 22:33:19 | Re: Advice: Where could I be of help? |
Previous Message | Zac Hillier | 2002-10-02 22:16:16 | foreach in sql functions |