Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/22.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
更新以从编号jsonb postgresql中删除双引号_Sql_Json_Postgresql_Select_Jsonb - Fatal编程技术网

更新以从编号jsonb postgresql中删除双引号

更新以从编号jsonb postgresql中删除双引号,sql,json,postgresql,select,jsonb,Sql,Json,Postgresql,Select,Jsonb,我正在使用PostgreSQL,并尝试运行jsonb的更新 我想把“2W”改成数字2 因此,下面的查询删除了W,但将其保留为“2” 我将如何删除双引号 目前它看起来像{“size”:“2W”},我希望它看起来像{“size”:2} 您可以使用来执行以下操作: jsonb_set(x, '{size}', to_jsonb(replace(x->>'size', 'W', '')::int)) : select jsonb_set(x, '{size}', to_jsonb(repl

我正在使用PostgreSQL,并尝试运行jsonb的更新

我想把“2W”改成数字2

因此,下面的查询删除了W,但将其保留为“2”

我将如何删除双引号

目前它看起来像{“size”:“2W”},我希望它看起来像{“size”:2}

您可以使用
来执行以下操作:

jsonb_set(x, '{size}', to_jsonb(replace(x->>'size', 'W', '')::int))

select jsonb_set(x, '{size}', to_jsonb(replace(x->>'size', 'W', '')::int))
from (values('{"size": "2W"}'::jsonb)) as t(x)
|jsonb_集| | :---------- | |{“大小”:2}| 如果需要,您可以将
::int
替换为
::numeric
,以处理十进制值。

您可以使用
来处理此问题:

jsonb_set(x, '{size}', to_jsonb(replace(x->>'size', 'W', '')::int))

select jsonb_set(x, '{size}', to_jsonb(replace(x->>'size', 'W', '')::int))
from (values('{"size": "2W"}'::jsonb)) as t(x)
|jsonb_集| | :---------- | |{“大小”:2}| 如果需要,可以将
::int
替换为
::numeric
,以处理十进制值