1

What are the pros and cons of setting the Postgres column as array in a migration vs using a string field with Serialize in a rails Model?

t.string :tags, array: true, default: []

vs

# Serialize a preferences attribute
class User < ActiveRecord::Base
  serialize :tags
end

This post mentioned some good notes on the topic, but would like more views: New data not persisting to Rails array column on Postgres Rails 4 field type for multiselect with predefined values

user2012677
  • 5,465
  • 6
  • 51
  • 113

1 Answers1

3

You can query and manipulate native PostgreSQL Array type using pure SQL whereas when using serialized attribute, querying and manipulating using SQL might be cumbersome and not as performant as native array type.

However if you plan or need the database technology to be interchangeable, using serialized attribute is database agnostic.

Ahmed Al Hafoudh
  • 8,281
  • 1
  • 18
  • 34