0

I have created the postgreSQL function below:

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;

it takes its format as input :

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

However I can't test with POSTMAN he interprets this as text and not JSON. do you have any ideas?

enter image description here

error message :

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

Thank you.

1
  • Try restarting PostgREST or sending it a SIGUSR1: kill -s SIGUSR1 $(pgrep postgrest) Commented Jan 18, 2021 at 18:35

1 Answer 1

1

The problem is type casting. The function expects parameters of types INT and NUMERIC. You are passing these parameters to JSON as strings. Try changing the request body.

{
     "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}
    ]
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.