Search Postgresql Archives

Re: Convert Arbitrary Table to Array?

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

 



In article <17050.1234200030@xxxxxxxxxxxxx>,
Tom Lane <tgl@xxxxxxxxxxxxx> writes:

> Lee Hughes <lee@xxxxxxxxxxxx> writes:
>> Hi, I need a function that accepts a table name and returns a 2-dimensional
>> array of the table data.

> Well, in 8.3 and up there are arrays of composite types, so you can
> do something like

> 		select array(select mytable from mytable);

Interesting.  On 8.3.5 I tried

  CREATE TABLE mytable (
    id serial NOT NULL,
    mytable int NOT NULL,
    PRIMARY KEY (id)
  );

  INSERT INTO mytable VALUES
    (1, 10),
    (2, 20),
    (3, 30),
    (4, 40),
    (5, 50),
    (6, 60);

  SELECT array(SELECT mytable FROM mytable);

and it returned

  {10,20,30,40,50,60}

Only when I renamed the second column from "mytable" to "mytablex" I got

  {"(1,10)","(2,20)","(3,30)","(4,40)","(5,50)","(6,60)"}

as you promised.  Is there any syntax for treating the first "mytable"
as a composite type name instead of a column name?


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