**已关闭。**此问题为not reproducible or was caused by typos。目前不接受回答。
这个问题是由错字或无法再重现的问题引起的。虽然类似的问题在这里可能是on-topic,但这个问题的解决方式不太可能帮助未来的读者。
8小时前关闭
Improve this question的
我试图查询一个JSON文件,以提取字段出来,并有问题。
这是我引用的JSON文件14.Json
{"ChannelReadings": [
{ "ReadingsDto": [
{
"Si": 47.67,
"Raw": 0,
"Conversion": 0,
"TimeStamp": "2023-01-24T12:57:43"
},
{
"Si": 47.22,
"Raw": 0,
"Conversion": 0,
"TimeStamp": "2023-01-24T13:02:43"
},
{
"Si": 47.6,
"Raw": 0,
"Conversion": 0,
"TimeStamp": "2023-01-24T13:07:43"
},
{
"Si": 47.5,
"Raw": 0,
"Conversion": 0,
"TimeStamp": "2023-01-24T13:12:43"
}
],
"ChannelId": 14
},
{
"ReadingsDto": [
{
"Si": 2.893605,
"Raw": 0,
"Conversion": 0,
"TimeStamp": "2023-01-24T13:07:43"
}
],
"ChannelId": 12
},
{
"ReadingsDto": [
{
"Si": 3.294233,
"Raw": 0,
"Conversion": 0,
"TimeStamp": "2023-01-24T13:07:43"
}
],
"ChannelId": 13
},
{
"ReadingsDto": [
{
"Si": 3.294233,
"Raw": 0,
"Conversion": 0,
"TimeStamp": "2023-01-24T13:07:43"
}
],
"ChannelId": 16
}
],
"DeviceSerialNumber": "894339",
"RestartPointerNo": 5514732,
"NewDownloadTable": false,
"DataHashDto": "5Mckxoq42EeLHmLnimXv6A=="
}
字符串
我可以使用以下代码成功地加载此
DROP TABLE IF EXISTS tmp;
CREATE TEMP table tmp (c TEXT );
COPY tmp FROM 'C:\ChrisDev\Readings\14.json' WITH (FORMAT TEXT, DELIMITER '~');
型
当我运行以下代码时:
select
c::json ->> 'DeviceSerialNumber' as SerialNumber,
(c::json ->> 'RestartPointerNo')::int as RestartPointerNo
from tmp
型
我得到以下错误:
[2023-11-16 23:42:08] [22P02] ERROR: invalid input syntax for type json
[2023-11-16 23:42:08] Detail: The input string ended unexpectedly.
[2023-11-16 23:42:08] Where: JSON data, line 1: {"ChannelReadings": [
型
Question我需要在这里做什么更改才能提取DeviceSerialNumber和RestartPointerNo的值
1条答案
按热度按时间gk7wooem1#
所以,按照尼克的建议,我从我的输入文件中删除了所有的CR LF代码,它工作了!