Re: Populating array of composite datatype

Поиск
Список
Период
Сортировка
От Raghavendra
Тема Re: Populating array of composite datatype
Дата
Msg-id CA+h6AhiaZSMrhbVXjy4gfi5SRfMHdh58Q3P=pqP=rVtwANyHig@mail.gmail.com
обсуждение исходный текст
Ответ на Populating array of composite datatype  (Sameer Thakur <samthakur74@gmail.com>)
Ответы Re: Populating array of composite datatype  (Chris Travers <chris.travers@gmail.com>)
Список pgsql-general
On Wed, Aug 7, 2013 at 4:04 PM, Sameer Thakur <samthakur74@gmail.com> wrote:
Hello,
I have a composite datatype abc which has two integer fields x,y.
I have a table Test which has an array of abc.
I am trying to populate Test. Tried 
insert into test values (ARRAY[abc(1,2)]); but got error 
ERROR:  function abc(integer, integer) does not exist

Is there anyway for doing this?


I think you need to use row() and explicit type cast.

postgres=# create type abc as (x integer, y integer);
CREATE TYPE
postgres=# create table foo(val abc[]);
CREATE TABLE
postgres=# insert into foo values (array[row(1,2)::abc]);
INSERT 0 1
postgres=# insert into foo values (array[row('1','2')::abc]);
INSERT 0 1
postgres=# select * from foo ;
    val
-----------
 {"(1,2)"}
 {"(1,2)"}
(2 rows)

---
Regards,
Raghavendra
EnterpriseDB Corporation

В списке pgsql-general по дате отправления:

Предыдущее
От: BladeOfLight16
Дата:
Сообщение: Re: Staging Database
Следующее
От: Chris Travers
Дата:
Сообщение: Re: Populating array of composite datatype