Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 50 lines (41 sloc) 1.845 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
PostgresArrays
==============

This library adds ability to use PostgreSQL array types with ActiveRecord.

    > User.find(:all, :conditions=>['arr @> ?', [1,2,3].pg])
      SELECT * FROM "users" WHERE ('arr' @> E'{"1", "2", "3"}')
    > User.find(:all, :conditions=>['arr @> ?', [1,2,3].pg(:integer)])
      SELECT * FROM "users" WHERE (arr @> '{1,2,3}')
    > User.find(:all, :conditions=>['arr @> ?', [1,2,3].pg(:float)])
      SELECT * FROM "users" WHERE (arr @> '{1.0,2.0,3.0}')
    > u = User.find(1)
      SELECT * FROM "users" WHERE ("users"."id" = 1)
      => #<User id: 1, ..., arr: [1,2]>
    > u.arr = [3,4]
    > u.save
      UPDATE "users" SET "db_ar" = '{3.0,4.0}' WHERE "id" = 19
    > User.find(:all, :conditions=>{:arr=>[3,4].pg})
      SELECT * FROM "users" WHERE ("users"."arr" = E'{"3", "4"}')
    > User.find(:all, :conditions=>{:arr=>[3,4].search_any(:float)})
      SELECT * FROM "users" WHERE ("users"."arr" && '{3.0,4.0}')
    > User.find(:all, :conditions=>{:arr=>[3,4].search_all(:integer)})
      SELECT * FROM "users" WHERE ("users"."arr" @> '{3,4}')
    > User.find(:all, :conditions=>{:arr=>[3,4].search_subarray(:safe)})
      SELECT * FROM "users" WHERE ("users"."arr" <@ '{3,4}')
      
      class U < ActiveRecord::Migration
        def self.up
          create_table :users do |t|
            t.integer_array :int_ar
          end
          add_column :users, :fl_ar, :float_array
        end
      end
      
Installation
============

    gem install ar_pg_array

Changelog
=========

  0.9.13

    Since version 0.9.13 ar_pg_array will try to detect arrays changed inplace.
    And parsed arrays are now cached in @attributes_cache.
    Thanks to Romain Beauxis (https://github.com/toots ) for being insistent about this.

Copyright (c) 2010 Sokolov Yura aka funny_falcon, released under the MIT license
Something went wrong with that request. Please try again.