微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

PostgreSQL数据类型:复合类型及其数组

只有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);

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐