I have defined a function in my PostgreSQL 10.18 database like this:
CREATE OR REPLACE FUNCTION public.log_event(event json)
RETURNS void
LANGUAGE 'plpgsql' AS
$BODY$
BEGIN
INSERT INTO "eventlog" VALUES(event::json->'event_type',
event::json->'message',
event::json->'user',
now());
END
$BODY$;
I can call it successfully from pgAdmin like this:
select log_event('{"event_type": "foo", "message": "bar", "user": "foobar"}'::json);
But when I try to call it from my Python code, that talks to the database via the PostGREST API:
event = {
"event": {
"event_type": "foo",
"message": "bar",
"user": "foobar"
}
}
requests.post('https://server/rpc/log_event', json=event)
It fails with:
{"hint":"No function matches the given name and argument types. You might need to add explicit type casts.",
"details":null,
"code":"42883",
"message":"function public.log_event(event => text) does not exist"}
What am I doing wrong?