这特别关于将数据插入CrateDB,
我有一个包含OBJECT类型列的表。我正在尝试使用python将JSON数据插入到它中,并且它很顺利。
创建表用户(userdata OBJECT);
但是,我的数据中有撇号,即单引号,因此插入失败。我在控制台上复制了这个问题:
以下数据中的问题是" snr"领域。我尝试过反斜杠,但这没有用。
有人可以告诉我如何获得以下插入
INSERT into users (userdata)
VALUES ('{"area_code": "2", "companyname": "TEC", "cos": "National24Hrs-Standard",
"country_code": "AUS", "cucm_dn": "26902", "ddi": "84236902", "department": null,
"device_type": "Cisco 8945 SIP", "divisionname": "Demonstrations",
"emailaddress": "bart.simpson@core.demo.telstra.com", "extension": "26902",
"extra1": null, "extra2": null, "extra3": null, "extra4": null,
"featuregroup": "Mobile Worker", "firstname": "Bart", "information": null,
"ippbxchosen": "TEC-CL-1", "language": "English - United States", "lastname": "Simpson",
"locationname": "Sydney", "mask": "61284236902", "pickupgroup": null, "postcode": "2000",
"presence": "Y", "role": "enduser", "security_profile": "EndUser-SP1",
"snr": "Bart\'s Mobile:0457503561,Bart Simpson:457503561",
"username": "bart.simpson@core.demo.telstra.com", "voicemail": "UCX-Advanced-CoS"}')
答案 0 :(得分:0)
将JSON string
插入到CrateDB object
类型列中将始终失败,这与您的案例中的错误转义无关。将其作为CrateDB对象(我猜你想要的)插入,以获得访问/搜索每个键/值的好处,或将数据类型更改为string
。
请参阅有关使用对象文字https://crate.io/docs/crate/reference/en/latest/general/ddl/data-types.html#object-literals的文档。 此外,大多数CrateDB客户端驱动程序都支持将数据绑定为对象。