My PostgrestSQL isn't recognizing my function parameter as JSON instead seems like I need to pass all the JSON entries.
I'm trying to create a new function in my PostgrestSQL that uses JSON as function argument, but then I got a problem. The problem is when I do a request to my endpoint I get this error:
{
"hint": "No function matches the given name and argument types. You might need to add explicit type casts.",
"details": null,
"code": "42883",
"message": "function rest_api.my_method(id => text) does not exist"
}
but in fact, this 'id' argument doesn't exist. Instead I'm passing a json as param. This error isn't able the function handle the body, it's throwing this error before.
That's how I wrote my function:
CREATE OR REPLACE FUNCTION rest_api.my_method(json)
RETURNS json
LANGUAGE 'plv8'
COST 100
VOLATILE PARALLEL UNSAFE
AS $BODY$
{
const jsonData = $1;
return jsonData;
}
$BODY$;
if I run this query
SELECT rest_api.my_method('{"key": "value"}');
it's returning the json {"key": "value"}
as it should do.