POSTMAN 中的 Json 参数与 postgreSQL 函数

问题描述

我在下面创建了 postgresql 函数

create or replace function analyse_lat(jsonvariable json) returns table (ok boolean,nb text) as 
$BODY$
declare 
    r record;
begin
    for r in (select * from json_to_recordset(jsonvariable->'list') as foo(id int,price1 numeric,price2 numeric)) loop
        --- DO THINGS
        ok:=(r.price1>r.price2);
        nb:='this is text returned';
        return next;
    end loop;
end;
$BODY$
language plpgsql;

它以它的格式作为输入:

{
     "users":"John","Level":"1","list":[
      {"id":"1","price1":"100.50","price2":"90.50"},{"id":"2","price1":"100.60","price2":"80.50"},"price1":"105.50","price2":"700.50"}
    ]
}

但是我不能用 POSTMAN 测试 他将其解释为文本而不是 JSON。你有什么想法吗?

enter image description here

错误信息:

{
    "hint": "No function matches the given name and argument types. You might need to add explicit type casts.","details": null,"code": "42883","message": "function analyse_lat(jsonvariable => text) does not exist"
}

谢谢。

解决方法

问题在于类型转换。该函数需要类型为 INTNUMERIC 的参数。 您将这些参数作为字符串传递给 JSON。尝试更改请求正文。

{
     "users":"John","Level":"1","list":[
      {"id":1,"price1":100.50,"price2":90.50},{"id":2,"price1":100.60,"price2":80.50},"price1":105.50,"price2":700.50}
    ]
}