微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

POSTMAN 中的 Json 参数与 postgreSQL 函数

如何解决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}
    ]
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。