Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/75.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/json/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
在PostgreSQL中,有选择地从json字段中删除双引号_Sql_Json_String_Postgresql - Fatal编程技术网

在PostgreSQL中,有选择地从json字段中删除双引号

在PostgreSQL中,有选择地从json字段中删除双引号,sql,json,string,postgresql,Sql,Json,String,Postgresql,我是PostgreSQL数据库的新用户,该数据库带有json字段,这给我带来了一些麻烦。 事实上,当字符串值被认为是数值时,字符串值已经用双引号插入到这个json字段中 我有一个名为“test_json”的字段,它由以下两行组成: {"test_name": "Full", "parameter1": "4.219", "parameter2": 4.4137} {"test_name&

我是PostgreSQL数据库的新用户,该数据库带有json字段,这给我带来了一些麻烦。 事实上,当字符串值被认为是数值时,字符串值已经用双引号插入到这个json字段中

我有一个名为“test_json”的字段,它由以下两行组成:

{"test_name": "Full", "parameter1": "4.219", "parameter2": 4.4137}
{"test_name": "Full", "parameter1": "3.758", "parameter2": 4.159} 
我希望以上两行在本表中更正后:

{"test_name": "Full", "parameter1": 4.219, "parameter2": 4.4137}
{"test_name": "Full", "parameter1": 3.758, "parameter2": 4.159}
我想更正这些值而不必删除所有内容,我无法手动更正,因为有成千上万个“parameter1”值。 你能帮我改正一下吗

我只想删除这个参数1的双引号,如果它不是数字的话

我发现所有具有此非数值参数1的行都带有:

select *
    from t_test_result
   where jsonb_typeof (t_test_result.test_json -> ' parameter1') <> 'number'
     and t_test_result.test_json ? 'parameter1'
选择*
根据t_测试结果
其中jsonb_typeof(t_test_result.test_json->“parameter1”)“number”
还有t_test_result.test_json?“参数1'
我想我以后必须使用更新功能,但我无法管理它

谢谢


Franck

您可以使用
jsonb_set()
来更改属性字节
参数1的值的数据类型:

update t_test_result
set test_json = jsonb_set(
    test_json, 
    '{parameter1}', 
    to_jsonb((test_json ->> 'parameter1')::numeric)
)
where test_json ? 'parameter1'