Skip to content

Instantly share code, notes, and snippets.

@saurabhnanda
Created December 5, 2013 12:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saurabhnanda/7804456 to your computer and use it in GitHub Desktop.
Save saurabhnanda/7804456 to your computer and use it in GitHub Desktop.
Checking Postgres array data-type support for activerecord-jdbc-adapter
require 'active_record'
require 'activerecord-jdbc-adapter'
ActiveRecord::Base.establish_connection({
:adapter => 'jdbcpostgresql',
:port => '5432'
})
conn=ActiveRecord::Base.connection
conn.execute("DROP TABLE IF EXISTS reproduce_bugs ")
conn.execute('CREATE TABLE reproduce_bugs(bool_array boolean[], str_2d_array character varying[][], num_array integer[])')
q = <<EOL
INSERT INTO reproduce_bugs(bool_array, str_2d_array, num_array) values('{f, t, t}', '{{"a", "b"}, {"c", "d"}}', '{1, 2, 3}')
EOL
conn.execute(q)
class ReproduceBug < ActiveRecord::Base; end
def assert_kind_of(klass, obj, msg = nil)
raise "Expected #{obj.inspect} to be of class #{klass.name}" if obj.class!=klass
end
x = ReproduceBug.first
assert_kind_of(Array, x.bool_array)
assert_kind_of(FalseClass, x.bool_array[0])
assert_kind_of(Array, x.str_2d_array)
assert_kind_of(Array, x.str_2d_array[0])
assert_kind_of(String, x.str_2d_array[0][0])
assert_kind_of(Array, x.num_array)
assert_kind_of(Fixnum, x.num_array[0])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment