Thread: Re: Postgresql 8.3X supports Arrays of Composite Types?

Re: Postgresql 8.3X supports Arrays of Composite Types?

From
Robson Fidalgo
Date:

Hello,
I am using postgresql 8.3X and I created a table (see example below) that has an attribute that is an Array of a Composite Type (ROW). However, I do not know how can I insert a record in this table.

Well, I've searched the mailing lists and have found little said about the OR features. In postgres 8.3X on-line documentation (http://www.postgresql.org/docs/8.3/static/arrays.html) I found "Arrays of any built-in or user-defined base type, enum type, or composite type can be created", however there is no example that explains how can I do an insert into an attribute that is an Array of Composite Type. Considering the example below, "persons have N phones" I create (with success) the Person table with an array of phones, but I have not success with Insert values. There is some one that can help me?

Thanks in advances,

Robson

Example:

CREATE table phone (
  cod varchar,
  num varchar);

CREATE TABLE person (
  name varchar,
  telephone phone[]);

Until here is everything ok, but I have not success with insert values, then I tried:

1)insert into person values ('Joe', '{("1","1111"),("2","2222") }');
2)insert into person values ('Joe', array[('1','1111'),('2','2222')]);
3)insert into person values ('Joe', array[row('1','1111'),row('2','2222')]);
4)insert into person values ('Joe', _phone[phone('1','1111'),phone('2','2222')]);**
** considering _phone = name of array type (automatically created by postgres) and phone = name of composite type (also automatically created by postgres)