在postgresql中的jsonb[]类型列中插入数据的正确语法是什么



由于我们只能将json对象的数组存储在jsonb列中,那么为什么要使用jsonb[]。我试图通过简单地将jsonb对象的数组从jsonb列复制到jsonb[]列,将数据插入jsonb[]中。但是得到错误";格式不正确的数组文字:必须引入显式指定的数组维度"。

[
{
"SchoolsCode": "",
"SchoolsName": "",
"SchoolsType": "High School",
"ErrorMessage": null,
"SchoolsDegree": "Doctoral Degree",
"BiskDocumentID": "",
"FailedAttempts": 0,
"SchoolsDegreeID": 2,
"ChecklistsHidden": "Active",
"ChecklistsStatus": "Received",
"ChecklistsSection": "Official Transcript",
"ChecklistsSubject": "High School Transcript (Bloomingdale High School)",
"SchoolMailingAddress": {
"City": "Windham",
"Region": "ME",
"Country": "United States",
"ZipCode": "",
"AddressStreet1": "406 Gray Rd",
"AddressStreet2": null
},
"SchoolsConferredDate": "2018-05-01",
"DocumentInformationID": 1,
"SchoolsAttendedToDate": "2018-07-01",
"SchoolsAttendedFromDate": "2014-04-01",
"IsSalesforceUpsertSuccess": true,
"IsStatusReceivedFromMaterialsEndpoint": true
},
{
"SchoolsCode": "",
"SchoolsName": "Bloomingdale High Scho",
"SchoolsType": "High School",
"ErrorMessage": null,
"SchoolsDegree": "Doctoral Degree",
"BiskDocumentID": "",
"FailedAttempts": 0,
"SchoolsDegreeID": 6,
"ChecklistsHidden": "Active",
"ChecklistsStatus": "Received",
"ChecklistsSection": "Official Transcript",
"ChecklistsSubject": "",
"SchoolMailingAddress": {
"City": "Windham",
"Region": "ME",
"Country": "United States",
"ZipCode": "",
"AddressStreet1": "406 Gray Rd",
"AddressStreet2": null
},
"SchoolsConferredDate": "2018-05-01",
"DocumentInformationID": 2,
"SchoolsAttendedToDate": "2018-07-01",
"SchoolsAttendedFromDate": "2014-04-01",
"IsSalesforceUpsertSuccess": true,
"IsStatusReceivedFromMaterialsEndpoint": true
},
{
"SchoolsCode": "",
"SchoolsName": "Governors State University",
"SchoolsType": "High School",
"ErrorMessage": null,
"SchoolsDegree": "Bachelor's Degree",
"BiskDocumentID": "fwafhawolef",
"FailedAttempts": 0,
"SchoolsDegreeID": 4,
"ChecklistsHidden": "Active",
"ChecklistsStatus": "Missing",
"ChecklistsSection": "Official Transcript",
"ChecklistsSubject": "High School Transcript (Bloomingdale High School)",
"SchoolMailingAddress": {
"City": "Windham",
"Region": "ME",
"Country": "United States",
"ZipCode": "04062",
"AddressStreet1": "406 Gray Rd",
"AddressStreet2": null
},
"SchoolsConferredDate": "2018-05-01",
"DocumentInformationID": 3,
"SchoolsAttendedToDate": "2018-07-01",
"SchoolsAttendedFromDate": "2014-04-01",
"IsSalesforceUpsertSuccess": true,
"IsStatusReceivedFromMaterialsEndpoint": true
}
]

试试这个:inserting-jsonb-data-inpostgresql-9-6

文档:该函数存在于postgres 9.6之后,函数jsonb-postgresql

简单插入也应该有效。例如:

INSERT INTO orders (info)
VALUES('{ "customer": "John Doe", "items": {"product": "Beer","qty": 6}}');

如果以上不起作用,请参阅此链接,此问题看起来与您的类似:https://stackoverflow.com/a/48866861/11094058

最新更新