Skip to content
Advertisement

Query JSONB column for any value where =?

I have a jsonb column which has the unfortunate case of being very unpredictable, in some cases its value may be an array with nested values:

Sometimes it will be something with key/values like this:

Is there a way to write a query which just treats the whole column like text and does a like to see if I can find the uuid in the big text blob? I want to find all the records where a particular uuid string is present in the jsonb column.

The query doesn’t need to be fast or efficient.

Advertisement

Answer

Postgres has search operator ? for jsonb, but that would require you to search the json content recursively.

A possible, although not very efficient method, would to stringify the object and use LIKE to search it:

Demo on DB Fiddle:

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement