0

我在下面创建了 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"},
      {"id":"2", "price1":"105.50", "price2":"700.50"}
    ]
}

但是我无法使用 POSTMAN 进行测试,他将其解释为文本而不是 JSON。你有什么想法?

在此处输入图像描述

错误信息 :

{
    "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"
}

谢谢你。

4

1 回答 1

1

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

{
     "users":"John",
     "Level":"1",
     "list":[
      {"id":1, "price1":100.50, "price2":90.50},
      {"id":2, "price1":100.60, "price2":80.50},
      {"id":2, "price1":105.50, "price2":700.50}
    ]
}
于 2021-01-15T18:52:42.360 回答