Json 带有 postgreSQL 函数的 POSTMAN 中的参数
Json parameter in POSTMAN with postgreSQL function
我在下面创建了 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"
}
谢谢。
问题是类型转换。该函数需要 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}
]
}
我在下面创建了 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"
}
谢谢。
问题是类型转换。该函数需要 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}
]
}