插入复合类型数组给出错误postgresql 9.4--

时间:2016-02-26 13:41:51

标签: arrays database postgresql postgresql-9.4

CREATE TABLE people(   
name_ varchar(50) NOT NULL,
count int NOT NULL DEFAULT 0
)

CREATE TABLE person_added(
date_ date NOT NULL,
all_people_ people[],
all_people_count int NOT NULL
)

CREATE TABLE all_people_array_table(
id SERIAL,
people_array person_added[]
)

INSERT INTO all_people_array_table(people_array) (SELECT ARRAY[CURRENT_DATE,  ARRAY[('Jack',3)::people,  ('John',6)::people], 1000]   )

我收到此错误;

错误:ARRAY类型日期和情感[]无法匹配

什么是正确的插入语句?

1 个答案:

答案 0 :(得分:0)

这对我有用:

insert into all_people_array_table(people_array)
select array[
    (current_date,
     array[
        ('Jack',3)::people,
        ('John',6)::people
     ], 1)::person_added
];