整数pgsql的输入语法无效

整数pgsql的输入语法无效,sql,json,postgresql,Sql,Json,Postgresql,我刚刚开始使用postgresql。表中有一个json对象。json对象中有一个数值,我想在其中添加一个数字并将其分配给其他整数。我就是这样做的 declare total_votes integer; .... select result into poll_result from polls where id = 1; total_votes = (select poll_result::json#>'{total_votes}'::integer + 1); 但这正在显示

我刚刚开始使用postgresql。表中有一个json对象。json对象中有一个数值,我想在其中添加一个数字并将其分配给其他整数。我就是这样做的

declare  
 total_votes integer;
....
select result into poll_result from polls where id = 1;
total_votes =  (select poll_result::json#>'{total_votes}'::integer + 1);
但这正在显示

ERROR:  invalid input syntax for integer: "{total_votes}"
LINE 1: SELECT (select poll_result::json#>'{total_votes}'::integer +...
poll_结果的数据如下

{
    "yes": 1,
    "no": 0,
    "total_votes": 1
}
当我尝试使用

RAISE NOTICE '%',poll_result::json#>'{total_votes};
它打印1

连我都试过了

total_votes =  (select (poll_result::json#>'{total_votes}')::integer + 1);
但是错误

ERROR:  cannot cast type json to integer
LINE 1: ...ELECT (select (poll_result::json#>'{total_votes}')::integer ...
操作符
#>
给出一个json,而
#>
给出一个文本,您需要第二个:

select (poll_result::json #>> '{total_votes}')::integer + 1

select (poll_result::json ->> 'total_votes')::integer + 1