Search Postgresql Archives

Re: Selecting from table into an array var

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



2009/12/19 Postgres User <postgres.developer@xxxxxxxxx>:
> Hi,
>
> I'm trying to write a very simple function statement to select a
> single integer field from a table and save it into an int array. For
> some reason I can't seem to find the correct syntax:
>
> CREATE TABLE sample (
>    id  integer
> );
>
> and then within a function:
>
> my_array int[];
> my_array = SELECT ARRAY(id) FROM sample;
>
>
> This syntax and variations of it don't work.  Can anyone show me the
> correct approach?
>

Hello

please try SELECT ARRAY(SELECT id FROM sample) or SELECT array_agg(id)
FROM sample - if you have 8.4

Regards
Pavel Stehule

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

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


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux