Postgresql – How to filter a value in json field type on Postgres 9.2

jsonpostgresqlpostgresql-9.2

My json field data is like this:

{"active":true,"id":"xxxxxxxxxxxxxxxxx","settings":{"secret":"xxxxxxxxxxxxxxxxxxxxxxxxxx","token":"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx","expires":"2019-12-16 01:11:23"},"plan":"Sample"}

Then I tried to query the field like this:

select * from integrations.accounts where field -> 'id' = 'xxxxxx';

But it gives me an error of:

SQL Error [42883]: ERROR: operator does not exist: json -> unknown

I found that the arrow operator (->) is not supported in version 9.2:

Unsupported versions: 9.3 / 9.2

Is there any alternative way to do this?

Best Answer

You would need the ->> operator instead:

select * from integrations.accounts where field ->> 'id' = 'xxxxxx';

But these operators were added with Postgres 9.3. Postgres 9.2 is just too old (and unsupported by now). It had barely more than the data type json itself. There seems to be a third-party extension "Json Enhancements for PostgreSQL 9.2":

But I have never tried it and would much rather upgrade to a current, supported version of Postgres instead. See: