On 3/13/07, Ezequias R. da Rocha <[EMAIL PROTECTED]> 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            | [EMAIL PROTECTED]
Iselin, New Jersey 08830            | http://www.enterprisedb.com/

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

               http://www.postgresql.org/about/donate

Reply via email to