加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

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

发布时间:2020-12-13 17:24:09 所属栏目:百科 来源:网络整理
导读:只有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);INSERTINTOs

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

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读