Answer the question
In order to leave comments, you need to log in
Is it safe to use jsonb in PostgreSQL?
Should I let users create fields inside jsonb? I would like to allow users to add any data they want to add. And display it on the page. How safe is it?
For example, give information about yourself. There are standard fields (city, date of birth, full name), but if suddenly people go to add something, they could easily do it.
Those. how vkontakte is displayed:
дата рождения такая-та дата
родной город Такой-то
телефон вот такой
#И тут уже поля, которые добавляют пользователи
Пользователь назвал поле А тут ответ на него
Пользователь назвал 2 И ответ на 2 поле
Answer the question
In order to leave comments, you need to log in
Is it safe?in general - no
Limit field size?no sense
Limit the number of custom fields?no sense
Why is this needed?except for caching. and to show that postgre is cooler than mongo
The speed of work and sampling?vibhorkumar.wordpress.com/2014/05/15/write-operati...
Maybe it's better to make an ordinary string, inside a text json and parse using javascript?if all this is not going to be used, then yes
There are modules for this. For example:
https://github.com/djangonauts/django-hstore stores a list of key-value pairs. In addition, you can set the scheme of custom fields - specify their list and types; in the model, in the ModelForm , in the admin panel, new fields appear, indistinguishable from the real ones, but actually stored in a column of type hstore.
https://github.com/bradjasper/django-jsonfield - already for full validated JSON.
Used these things two times, namely the first library. You can change the scheme depending on the different parameters of the model, everything is very beautiful and convenient. In production, however, for various reasons, it hasn't hit yet. I don’t know, maybe I’ll get to combat use.
In general, it is very inconvenient that such liberties with the schema in relational DBMS are made so difficult and crutch-like.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question