I
I
Ivan2019-03-06 18:55:56
PostgreSQL
Ivan, 2019-03-06 18:55:56

How to properly implement search in PostgreSQL by json?

There is a bulletin board and in it - a block with a filter, and the user can save the selected parameters to his bookmarks, before sending to the database, the parameters go through json_encode .
When an ad is added that matches the saved parameters, the person needs to be notified to do this, they need to do a search in the column with the saved parameters.
Question : how best to implement such functionality?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Artem Cherepakhin, 2019-03-14
@AltZ

And what exactly is the problem?
Do you put all the json in the database? Or do you have a normalized representation of the parameters?
1) If all json then create functional indexes on column with json like https://stackoverflow.com/questions/36075918/postg... .
2) You can still use normalization and create a table with accumulating parameters with fields (id_user, param1, param2 ...) and save the data to the table. the parameter column takes the value 0, 1. and do indexes on the columns. True, there may be difficulties when adding a new field (read, parameter).
If you calculate the cost of hemorrhoid solutions, then 1e is more profitable.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question