Received: from localhost (maia-4.hub.org [200.46.204.183]) by postgresql.org (Postfix) with ESMTP id 434199FB60B for ; Tue, 13 Mar 2007 10:39:40 -0300 (ADT) Received: from postgresql.org ([200.46.204.71]) by localhost (mx1.hub.org [200.46.204.183]) (amavisd-new, port 10024) with ESMTP id 72820-09 for ; Tue, 13 Mar 2007 10:39:29 -0300 (ADT) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.4 Received: from ug-out-1314.google.com (ug-out-1314.google.com [66.249.92.172]) by postgresql.org (Postfix) with ESMTP id 951B59FB5A5 for ; Tue, 13 Mar 2007 10:39:29 -0300 (ADT) Received: by ug-out-1314.google.com with SMTP id k3so254616ugf for ; Tue, 13 Mar 2007 06:39:28 -0700 (PDT) DKIM-Signature: a=rsa-sha1; c=relaxed/relaxed; d=gmail.com; s=beta; h=domainkey-signature:received:received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=EdunnOmHOA+mXbqPfoF4ouqtCRv0a1xclBN7YOcz9VWpTYGTb8TzCVZSNM/Tdyt75A/x7otwvtzBNqaVpn0iV2kEm4ZPhrsVzy+hxMOWEM3Sbq1gGhole95X6T073TU23HMIxq0jg9XsCr0SKe4JwADz+RUVWfrKIpEbhokj5n0= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=beta; h=received:message-id:date:from:to:subject:cc:in-reply-to:mime-version:content-type:content-transfer-encoding:content-disposition:references; b=J3Y26xv/ITc7FT9yRixEwrnXX4To9ubHCLIauPWvyQy2rZP53BamlqR0uG84HvSQyRwvsgjeJVTnuBn0ALDN7d/2m1MJkD/+S9LLtxUmSn6SUceanqib3D++s8S6Sq0cIF0mln5QgcrbqlHfcWHL0+MbyAePkLcxvz4vP6KYqwY= Received: by 10.115.89.1 with SMTP id r1mr2405005wal.1173793167073; Tue, 13 Mar 2007 06:39:27 -0700 (PDT) Received: by 10.114.181.14 with HTTP; Tue, 13 Mar 2007 06:39:27 -0700 (PDT) Message-ID: <36e682920703130639i4bce82beg1bcab46dd16240ab@mail.gmail.com> Date: Tue, 13 Mar 2007 09:39:27 -0400 From: "Jonah H. Harris" To: "Ezequias R. da Rocha" Subject: Re: For loop Cc: pgsql-sql@postgresql.org In-Reply-To: <45F6A793.1090904@fastcon.com.br> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline References: <45F69D7C.4070304@fastcon.com.br> <45F6B1A2.A3DD.0030.0@indicator.be> <45F6B4EB.A3DD.0030.0@indicator.be> <45F6A793.1090904@fastcon.com.br> X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 200703/160 X-Sequence-Number: 27798 On 3/13/07, Ezequias R. da Rocha 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/