这里我创建了一个使用json_populate_recordset
函数的类型。
CREATE TYPE Visits_type AS
(facilityId varchar,patientId varchar,encounterId numeric,patientClass varchar,admnDate varchar,dischargeDate varchar,practitionerId varchar,
careLocationType varchar,careLocationCode varchar,specialtyCode varchar,status varchar,admitPractitionerId varchar,hpSeqNo varchar,admissionType varchar,assignedRoom varchar,assignedBed varchar,
Firstname varchar,
Patientname varchar,
Firstnamelocal varchar,
Patientnamelocal varchar,
sex varchar,
Dob varchar,
Mobilenumber varchar,
Emailid varchar,
RegnFacilityid varchar);
使用示例sql和json:
SELECT * from json_populate_recordset(null::Visits_type, '[
{
"facilityId": "10","patientId": "GH00000940","encounterId": 100011770001,"patientClass": "OP","admnDate": "2015-05-17 17:25","dischargeDate": null,"practitionerId": "ALLEN","careLocationType": "C","careLocationCode": "CL11","specialtyCode": "SP11", "status": "E", "admitPractitionerId": null, "hpSeqNo": 3796, "admissionType": "First Visit", "assignedRoom": "R1", "assignedBed": null, "firstName": "Suresh", "patientName": "Suresh Machwal", "firstNameLocal": null, "patientNameLocal": null, "sex": "M", "dob": "1970-05-17", "mobileNumber": null, "emailId": null, "regnFacilityId": "GH" }, {
"facilityId": "10",
"patientId": "GH00000940",
"encounterId": 100011770001,
"patientClass": "OP",
"admnDate": "2015-05-17 17:25",
"dischargeDate": null,
"practitionerId": "ALLEN",
"careLocationType": "C",
"careLocationCode": "CL11",
"specialtyCode": "SP11",
"status": "E",
"admitPractitionerId": null,
"hpSeqNo": 3795,
"admissionType": "First Visit",
"assignedRoom": "R1",
"assignedBed": null,
"firstName": "Suresh",
"patientName": "Suresh Machwal",
"firstNameLocal": null,
"patientNameLocal": null,
"sex": "M",
"dob": "1970-05-17",
"mobileNumber": null,
"emailId": null,
"regnFacilityId": "GH"
}]');
问题是它为所有字段返回空值,但dob
,status
和sex
除外。
答案 0 :(得分:1)
在创建类型时,您应该使用双引号来保留原始案例:
CREATE TYPE Visits_type AS
("facilityId" varchar,
"patientId" varchar,
"encounterId" numeric,
"patientClass" varchar,
"admnDate" varchar,
"dischargeDate" varchar,
"practitionerId" varchar,
"careLocationType" varchar,
"careLocationCode" varchar,
"specialtyCode" varchar,
"status" varchar,
"admitPractitionerId" varchar,
"hpSeqNo" varchar,
"admissionType" varchar,
"assignedRoom" varchar,
"assignedBed" varchar,
"Firstname" varchar,
"Patientname" varchar,
"Firstnamelocal" varchar,
"Patientnamelocal" varchar,
"sex" varchar,
"Dob" varchar,
"Mobilenumber" varchar,
"Emailid" varchar,
"RegnFacilityid" varchar);