From: | "Jonah H(dot) Harris" <jonah(dot)harris(at)gmail(dot)com> |
---|---|
To: | "Ezequias R(dot) da Rocha" <ezequias(at)fastcon(dot)com(dot)br> |
Cc: | pgsql-sql(at)postgresql(dot)org |
Subject: | Re: For loop |
Date: | 2007-03-13 13:39:27 |
Message-ID: | 36e682920703130639i4bce82beg1bcab46dd16240ab@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
On 3/13/07, Ezequias R. da Rocha <ezequias(at)fastcon(dot)com(dot)br> wrote:
> I quetion one more time. I must have a function ? Isn't another way to
> implement it without using functions ?
Not in PostgreSQL. Here's a sample of something similar to what you were doing.
CREATE LANGUAGE plpgsql;
CREATE TABLE carga (
id NUMERIC,
desc_txt TEXT,
PRIMARY KEY (id));
CREATE OR REPLACE FUNCTION for_loop_func (num_iter INTEGER)
RETURNS void AS
$$
DECLARE
iter NUMERIC;
tmp_num NUMERIC;
BEGIN
FOR iter IN 1 .. num_iter
LOOP
-- some computations
tmp_num = iter * 2;
INSERT INTO carga
(id, desc_txt)
VALUES (tmp_num, 'My Text for ' || iter || '*2 = ' || tmp_num);
END LOOP;
RETURN;
END;
$$ LANGUAGE plpgsql;
--SELECT for_loop_func(1000000);
SELECT for_loop_func(10);
--
Jonah H. Harris, Software Architect | phone: 732.331.1324
EnterpriseDB Corporation | fax: 732.331.1301
33 Wood Ave S, 3rd Floor | jharris(at)enterprisedb(dot)com
Iselin, New Jersey 08830 | http://www.enterprisedb.com/
From | Date | Subject | |
---|---|---|---|
Next Message | Alvaro Herrera | 2007-03-13 13:40:41 | Re: For loop |
Previous Message | Adrian Klaver | 2007-03-13 13:32:34 | Re: For loop |