I'm using (or trying to) the following function:
CREATE FUNCTION replace_value(data JSON, key text, value anyelement)
RETURNS JSON AS $$
import json
d = json.loads(data)
d[key] = value
return json.dumps(d)
$$ LANGUAGE plpython3u;
This, as I did not expect, does not work. Postgres complains:
ERROR: PL/Python functions cannot accept type anyelement
Well... that's just silly, because native Python functions can accept anything of any type, since variables are just names for things.
And in this case, I could not care what the actual type of the value is, I just want to be able to replace it. How can I do such a thing in Postgres/PLPython?