只有int类型时:
createtypepersonas(idint,ageint); createtablestu2(infoperson[2],markint); INSERTINTOstu2(info,mark)values(ARRAY[CAST(row(2,22)ASperson),CAST(row(2,24)ASperson)],98); INSERTINTOstu2values('{"(2,22)","(3,23)"}',98); INSERTINTOstu2(info[0],info[1],mark)values((2,22),(4,24),100); INSERTINTOstu2(info[0].id,info[0].age,info[1].id,info[1].age,mark)values(2,22,4,24,100);
int和char混合时:
创建复合类型
CREATETYPEinventory_itemAS( nametext,supplier_idinteger,pricenumeric);
使用复合类型
CREATETABLEon_hand( iteminventory_item,countinteger); INSERTINTOon_hand(item,count)VALUES(('fuzzydice',42,4),55);
复合类型的数组
CREATETABLEon_hand2(iteminventory_item[2],countinteger); INSERTINTOon_hand2values('{"(\"ddd\",44,"(\"dddd\",3,98); INSERTINTOon_hand2values(array[CAST(ROW('aaaa',23)ASinventory_item),CAST(ROW('dddd',23)ASinventory_item)],98); INSERTINTOon_hand2(item[0].name,item[0].supplier_id,item[0].price,count)VALUES('fuzzydice',3444); INSERTINTOon_hand2(item[0],item[1],('fff',33,66),55);原文链接:https://www.f2er.com/postgresql/195478.html