Postgres array support for Active Record
Latest commit e3d5b1f Sep 9, 2013 Tim Connor Fix issue caused by merge
Failed to load latest commit information.
spec Add test case for issue#23 Feb 21, 2013
.gitignore added regexp for validating postgres arrays and specs for the regexp Jan 23, 2012
Gemfile explicitly require postgres adapter (fixes combustion issues) Jan 26, 2012
LICENSE Add License Dec 12, 2011
README.textile Remove monkey patch of activerecord Feb 15, 2013
Rakefile added regexp for validating postgres arrays and specs for the regexp Jan 23, 2012
activerecord-postgres-array.gemspec Fix issue caused by merge Sep 9, 2013


Postgres array support for activerecord

Add basic support for postgres arrays to activerecord, with special attention to getting rails migrations / schema dumps working nicely.


gem install activerecord-postgres-array

or if you use bundler

gem 'activerecord-postgres-array'


  • In your migrations you can define postgres array fields such as:
    create_table :people do |t|
      t.string_array :real_energy
      t.decimal_array :real_energy, :precision => 18, :scale => 6
  • When queried, the postgres arrays will be returned as ruby arrays, and vice versa.

Compatibility with activerecord-postgres-hstore


As of activerecord-postgres-hstore ‘0.7.0’, ActiveRecord::Base#arel_attributes_value is not monkey patched and therefore does not interfere with loading of this gem.

If you are using ‘0.6.0’, or earlier, of activerecord-postgres-hstore you must use this gem’s version ‘0.0.8’ and the following still applies:

activerecord-postgres-hstore and activerecord-postgres-array both monkeypatch ActiveRecord::Base#arel_attributes_values, which leads to problems if these gems are used together. This gem is aware of activerecord-postgres-hstore and incorporates it in the monkeypatch. However, it is important that activerecord-postgres-array is loaded after activerecord-postgres-hstore for this to work.

Current limitations

  • Parsing of multi-dimensional postgres array strings is currently not implemented.
  • String, Decimal and Integer arrays have been tested, but other array types have not been. Type casting will need to be implemented for booleans, dates, etc

Future enhancements

  • Arel like querying of values within arrays
  • Arel like aggregate functions