pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
select result into string's array
4+ messages / 3 participants
[nested] [flat]

* select result into string's array
@ 2009-10-09 07:30 Alberto Asuero Arroyo <albertoasuero@gmail.com>
  2009-10-09 07:45 ` Re: select result into string's array A. Kretschmer <andreas.kretschmer@schollglas.com>
  2009-10-09 08:31 ` Re: select result into string's array Dmitriy Igrishin <dmitigr@gmail.com>
  0 siblings, 2 replies; 4+ messages in thread

From: Alberto Asuero Arroyo @ 2009-10-09 07:30 UTC (permalink / raw)
  To: pgsql-sql

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,





^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: select result into string's array
  2009-10-09 07:30 select result into string's array Alberto Asuero Arroyo <albertoasuero@gmail.com>
@ 2009-10-09 07:45 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
  1 sibling, 0 replies; 4+ messages in thread

From: A. Kretschmer @ 2009-10-09 07:45 UTC (permalink / raw)
  To: pgsql-sql

In response to Alberto Asuero Arroyo :
> Hi,
> 
> I need to store the result of select into an array of string:

test=*# select * from foo;
  t
------
 foo
 bar
 batz
(3 rows)

test=*# select array_agg(t) from foo;
   array_agg
----------------
 {foo,bar,batz}
(1 row)

Helps that?


Andreas
-- 
Andreas Kretschmer
Kontakt:  Heynitz: 035242/47150,   D1: 0160/7141639 (mehr: -> Header)



^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: select result into string's array
  2009-10-09 07:30 select result into string's array Alberto Asuero Arroyo <albertoasuero@gmail.com>
@ 2009-10-09 08:31 ` Dmitriy Igrishin <dmitigr@gmail.com>
  2009-10-09 09:08   ` Re: select result into string's array Alberto Asuero Arroyo <albertoasuero@gmail.com>
  1 sibling, 1 reply; 4+ messages in thread

From: Dmitriy Igrishin @ 2009-10-09 08:31 UTC (permalink / raw)
  To: Alberto Asuero Arroyo <albertoasuero@gmail.com>; +Cc: pgsql-sql

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 <albertoasuero@gmail.com>

> 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
>

^ permalink  raw  reply  [nested|flat] 4+ messages in thread

* Re: select result into string's array
  2009-10-09 07:30 select result into string's array Alberto Asuero Arroyo <albertoasuero@gmail.com>
  2009-10-09 08:31 ` Re: select result into string's array Dmitriy Igrishin <dmitigr@gmail.com>
@ 2009-10-09 09:08   ` Alberto Asuero Arroyo <albertoasuero@gmail.com>
  0 siblings, 0 replies; 4+ messages in thread

From: Alberto Asuero Arroyo @ 2009-10-09 09:08 UTC (permalink / raw)
  To: Dmitriy Igrishin <dmitigr@gmail.com>; +Cc: pgsql-sql

Dmitriy Igrishin wrote:
> 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 <albertoasuero@gmail.com
> <mailto:albertoasuero@gmail.com>>
>
>     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
>     <mailto:pgsql-sql@postgresql.org>)
>     To make changes to your subscription:
>     http://www.postgresql.org/mailpref/pgsql-sql
>
>


It's has been really useful for my  to solve the dinamic Record
Introspection problem that I had.

Thanks,

Alberto




^ permalink  raw  reply  [nested|flat] 4+ messages in thread


end of thread, other threads:[~2009-10-09 09:08 UTC | newest]

Thread overview: 4+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2009-10-09 07:30 select result into string's array Alberto Asuero Arroyo <albertoasuero@gmail.com>
2009-10-09 07:45 ` A. Kretschmer <andreas.kretschmer@schollglas.com>
2009-10-09 08:31 ` Dmitriy Igrishin <dmitigr@gmail.com>
2009-10-09 09:08   ` Alberto Asuero Arroyo <albertoasuero@gmail.com>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox