简体   繁体   中英

What is the correct syntax of inserting the data inside the jsonb[] type column inside postgresql

As we can store the array of json object inside the jsonb column only, then why to use the jsonb[]. I was trying to insert the data inside the jsonb[], by simply copying the array of jsonb object from jsonb column to jsonb[] column. But Getting error "Malformed Array Literals : must introduce explicitly specified array dimension".

[
  {
    "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
  }
]

Try with this : inserting-jsonb-data-in-postgresql-9-6

Documentation : The function exists from postgres 9.6 onwards, funtions-jsonb-postgresql

Simple Insert should also work. eg:

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

If above doesnt work, refer this link, This issue looks similar to yours : https://stackoverflow.com/a/48866861/11094058

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM