We have a large amount of PLPGSQL code that inserts/update json data into JSON columns using Postgres 9.3
We want to convert the code over time to move to the JSONB format and take advantage of the better indexing and new operators.
Is there a way of doing this without rewriting all of our code to use the new JSONB format.
For example, we have a lot of functions that accept and return JSON, crude example:-
FUNCTION foo(payload JSON) RETURNS JSON AS
$$
BEGIN
...
INSERT INTO baa(json, name) VALUES(payload, 'name');
RETURN '{"message" : "done"}'::JSON
END
$$ LANGUAGE PLPGSQL;
My ideal would be something that CASTS the json to jsonb without having to rewrite the function. I tried a trigger function to do this prior to insert but this does not work as the postgres query syntax checker gets there first:-
ERROR: column "json" is of type jsonb but expression is of type json
I suspect there is nothing I can do and will have to rewrite all of the code (1000s of lines), but thought I'd put this out there to see if there is a clever idea that could allow me to do the CAST on insert/update and buy some time for the rewrite.