G
G
GrimJack2017-09-08 17:33:26
PostgreSQL
GrimJack, 2017-09-08 17:33:26

What is the best way to search by json cell?

I am writing a project on laravel, as a postgres database (I hope this will somehow help).
There is a field in the json table that stores an array in the form (array A) ['0', '12', '3']
And there is another array (array B) ['0', '5', '7']
And now you need to make a request, where at least one value from array B matches array A. You need to do it at the request level in the database, so as not to receive and not process unnecessary data.
What are the ways to do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2017-09-08
@GrimJack

SELECT *
FROM table
WHERE a::jsonb ?| ARRAY(SELECT json_array_elements_text(b))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question