1

As specified in this other question you can store serialized data in the database. What i want to know is if i really should or just create a simple extra table.

Object has a list of asociated numbers.

Will probably need to check if an object has a particular number.

Will never update it.

Wont query it.

Have property numbers as serialize?

Have table Numbers belonging to Objects?

BTW im using rails 5.1 and postgresql.

Thanks

1 Answer 1

2

Since you're using PostgreSQL, you actually have a third option: use an array column.

Add the array: true option when creating the column:

t.integer :column_name, array: true

and then model.column_name will be a Ruby array and you can use all the PostgreSQL array operators and functions to work with and query the array.

I tend to think that you're usually better off with a separate table but an array column is often convenient and fairly easy to unroll into a separate table if necessary.

I'd stay away from serialize. That throws a blob of YAML into your database and YAML is difficult and cumbersome to query let alone manipulate inside the database.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, accidental submit. Thanks. I deleted my answer and will delete this comment as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.