postgresql 22 P02错误:Postgres中json -> JSON类型的输入语法无效[已关闭]

3vpjnl9f  于 2023-11-18  发布在  PostgreSQL
关注(0)|答案(1)|浏览(163)

**已关闭。**此问题为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的值

gk7wooem

gk7wooem1#

所以,按照尼克的建议,我从我的输入文件中删除了所有的CR LF代码,它工作了!

相关问题