class Marriage(BaseModel):
users = ArrayField(BigIntegerField)
chat_id = BigIntegerField()
class Meta:
indexes = (
(('users', "chat_id"), True),
)
I would like to make a unique index for both user values and chat_id for example:
there is already such a row in the database:
users=[1,2], chat_id=1
I would like to create the same but a different position in the user array.
users=[2,1], chat_id=1
2
Answers
I’d suggest consulting the Postgres folks as I’m not sure how you’d do that. I think the "best" solution is to store them flat:
Then to get all users for a marriage:
In Postgres you create a unique index and order the values of (user_id, chat_id) using the least(), greatest() functions as follows: (see demo)
I am not sure how this exactly translates into your obscurification language. But would seem doable looking how you created the index in your code.