只有int类型时:
create type person as(id int,age int);
create table stu2( info person[2], mark int);
INSERT INTO stu2(info,mark) values(ARRAY[CAST(row(2,22) AS person),CAST(row(2,24) AS person)],98);
INSERT INTO stu2 values('{"(2,22)","(3,23)"}',98);
INSERT INTO stu2(info[0],info[1], mark) values((2,22),(4,24),100);
INSERT INTO stu2(info[0].id,info[0].age,info[1].id,info[1].age, mark) values(2,22,4,24,100) ;
int和char混合时:
创建复合类型
CREATE TYPE inventory_item AS (
name text,
supplier_id integer,
price numeric );
使用复合类型
CREATE TABLE on_hand (
item inventory_item,
count integer );
INSERT INTO on_hand(item,count) VALUES (('fuzzy dice', 42, 4),55);
复合类型的数组
CREATE TABLE on_hand2 ( item inventory_item[2], count integer );
INSERT INTO on_hand2 values('{"(\"ddd\",44,22)","(\"dddd\",3,23)"}',98);
INSERT INTO on_hand2 values(array[CAST (ROW('aaaa',3,23) AS inventory_item),CAST(ROW('dddd',3,23) AS inventory_item)] ,98);
INSERT INTO on_hand2(item[0].name,item[0].supplier_id,item[0].price,count) VALUES ('fuzzy dice', 42, 4, 3444);
INSERT INTO on_hand2(item[0],item[1],count) VALUES (('fuzzy dice', 42, 4),('fff', 33, 66),55);