Received: from maia.hub.org (unknown [200.46.204.183]) by mail.postgresql.org (Postfix) with ESMTP id BACFC6336D9 for ; Fri, 9 Oct 2009 05:31:34 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.183]) (amavisd-maia, port 10024) with ESMTP id 59029-09 for ; Fri, 9 Oct 2009 08:31:26 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-ew0-f218.google.com (mail-ew0-f218.google.com [209.85.219.218]) by mail.postgresql.org (Postfix) with ESMTP id 2511F63239A for ; Fri, 9 Oct 2009 05:31:25 -0300 (ADT) Received: by ewy18 with SMTP id 18so991049ewy.19 for ; Fri, 09 Oct 2009 01:31:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:cc:content-type; bh=1yMLk+j2viazbDKjaK7bblF5BpEnRfO0j79RuhcbW0Q=; b=ZZfVyPudWsUp+UNGI5gNQF0fkq+DBe9v7ZM8eU53QAsoA4DUA5Q5BBiT8t51ajnLwD WFEuix2MvLHISlFuFVLrNahroqHi3BKCVZEmODPDUfeoUStKaZx7tFyBpJ4I4sUFvyAQ +PJBOsiaPjGeNdEIaKe98udDmJ8AnCmdnVXig= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; b=WYzivySFuzrCakZHJtBByx37RxCGY9BvdJsWFGL3Vmi/bSKdhH6FZnLxRloSP46y5M HkKoEh4b6lIUh9u/c5Mt/xA61Tqg53WeE1ZroQZrffFkMjQV4paw85pUY10edM4CjaEd cagCWmTIbrQhIvK+NJd5fD/circ4vtGa87BHw= MIME-Version: 1.0 Received: by 10.211.173.11 with SMTP id a11mr2852202ebp.42.1255077084171; Fri, 09 Oct 2009 01:31:24 -0700 (PDT) In-Reply-To: <4ACEE6A3.4090901@gmail.com> References: <4ACEE6A3.4090901@gmail.com> Date: Fri, 9 Oct 2009 12:31:24 +0400 Message-ID: Subject: Re: select result into string's array From: Dmitriy Igrishin To: Alberto Asuero Arroyo Cc: pgsql-sql@postgresql.org Content-Type: multipart/alternative; boundary=00504502c864c491e204757c672e X-Virus-Scanned: Maia Mailguard 1.0.1 X-Spam-Status: No, hits=-2.598 tagged_above=-10 required=5 tests=BAYES_00=-2.599, HTML_MESSAGE=0.001 X-Spam-Level: X-Archive-Number: 200910/32 X-Sequence-Number: 33231 --00504502c864c491e204757c672e Content-Type: text/plain; charset=ISO-8859-1 Hello. You should use an array constructor: DECLARE m_array text[]; [..] BEGIN FOR m_array IN SELECT ARRAY[col_1, col_2, col_N] FROM my_table LOOP [..] END LOOP; Regards, Igrishin Dmitriy. 2009/10/9 Alberto Asuero Arroyo > Hi, > > I need to store the result of select into an array of string: > > /create or replace function search_engine.test/ > /(/ > /)/ > / returns integer as $$/ > /declare/ > / m_array text[];/ > /begin/ > / for m_array in select * from my_table loop/ > / raise notice 'valor 1: %',m_array;/ > / end loop;/ > / return 1;/ > /end; $$ LANGUAGE plpgsql;/ > > > This launch this errors: > > /ERROR: array value must start with "{" or dimension information > SQL state: 22P02 > Context: PL/pgSQL function "test" line 4 at FOR over SELECT rows/ > > > Is it possible do this?? May I choose another way? > > Thanks in advance > > Alberto, > > > > -- > Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) > To make changes to your subscription: > http://www.postgresql.org/mailpref/pgsql-sql > --00504502c864c491e204757c672e Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable Hello.

You should use an array constructor:

DECLARE
=A0=A0= =A0 m_array text[];
=A0=A0=A0 [..]
BEGIN
FOR m_array IN SELECT ARR= AY[col_1, col_2, col_N] FROM my_table LOOP
[..]
END LOOP;

Rega= rds,
Igrishin Dmitriy.

2009/10/9 Alberto Asuero Arroyo <albertoasuero@gmail.co= m>
Hi,

I need to store the result of select into an array of string:

=A0 =A0/create or replace function search_engine.test/
=A0 =A0/(/
=A0 =A0/)/
=A0 =A0/ =A0 =A0returns integer as $$/
=A0 =A0/declare/
=A0 =A0/ =A0 =A0m_array text[];/
=A0 =A0/begin/
=A0 =A0/ =A0 =A0for m_array in select * from my_table loop/
=A0 =A0/ =A0 =A0 =A0 =A0raise notice 'valor 1: %',m_array;/
=A0 =A0/ =A0 =A0end loop;/
=A0 =A0/ =A0 =A0return 1;/
=A0 =A0/end; $$ LANGUAGE plpgsql;/


This launch this errors:

=A0 =A0/ERROR: array value must start with "{" or dimension info= rmation
=A0 =A0SQL state: 22P02
=A0 =A0Context: PL/pgSQL function "test" line 4 at FOR over SELE= CT rows/


Is it possible do this?? May I choose another way?

Thanks in advance

Alberto,



--
Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
To make changes to your subscription:
= http://www.postgresql.org/mailpref/pgsql-sql

--00504502c864c491e204757c672e--