One solution is to use hstore instead of json field type. The problem with this is casting your existing json to hstore.
Another solution is to use GROUP BY, instead of SELECT DISTINCT, in your queries.
But there are some cases where it would be easier to just change the field type to hstore, for example when using active admin.
I had a HABTM association in one of my models, and active admin would try to query:
db_dev=# SELECT DISTINCT "api_v1_test".* FROM "api_v1_test" INNER JOIN "api_v1_test_users" ON "api_v1_test"."id" = "api_v1_test_users"."test_id" WHERE "api_v1_test_users"."user_id" = 200;
ERROR: could not identify an equality operator for type json
LINE 1: SELECT DISTINCT "api_v1_test".* FROM "api_v1_test" INNER JOI...
Without wanting to spend much time fixing this and figuring out how to rewrite these queries I just converted the field to a hstore and everything is now working as it should.
Also, can you not enter a psql console from heroku to create your functions? or create a new migration for them?