I'm working on a project where each user has an inventory, which is really just an array of IDs that correspond to actual things in the project.
To store the inventory, I want to use Postgres and just serialize/deserialize data into a string format. However, in this array it is likely that they will have many of a single ID. The IDs are all integers so I'm planning on just joining them with a comma and separating them out during retrieval.
For example, the inventory might be [1, 2, 3, 3, 3, 4]
, but it would be best not to store it like 1,2,3,3,3,4
with a long repeating list.
Is there an efficient way to store duplicate items?
int[]
column. Or just use a separate table so that you can have proper referential integrity in your database. Also, how huge are these arrays and how many duplicates do they have that you think this sort of optimization is necessary?