Re: For loop
| От | Jonah H. Harris |
|---|---|
| Тема | Re: For loop |
| Дата | |
| Msg-id | 36e682920703130639i4bce82beg1bcab46dd16240ab@mail.gmail.com обсуждение исходный текст |
| Ответ на | Re: For loop ("Ezequias R. da Rocha" <ezequias@fastcon.com.br>) |
| Список | pgsql-sql |
On 3/13/07, Ezequias R. da Rocha <ezequias@fastcon.com.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@enterprisedb.com
Iselin, New Jersey 08830 | http://www.enterprisedb.com/
В списке pgsql-sql по дате отправления: