Immediate problem: type json
There are no equality or inequality operators defined for the Postgres data type json. See:
How to query a json column for empty objects?
How to remove known elements from a JSON array in PostgreSQL?
Hence row comparisons involving a json column are also bound to fail - with notable exceptions, see below.
There are (imperfect!...
I find pl/pgsql tedious for general programming, and slow to program in and slow to execute. And missing a lot of functionality--some of which is missing because it has to be in order to be a trusted language (no IPC or network), and others just because it hasn't been built and it lacks a mechanism for libraries/modules/packages.
I've used plpython3u get ...