diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-17 10:56:39 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-17 10:56:39 -0700 |
commit | 8067857bdfcea7bb1f916613dabfc96502932fbf (patch) | |
tree | 3732ac834a45ab2ecccbbd685e53ba4b73b9643a | |
parent | 165acf393fc16a89770829284ec3faa52844800f (diff) | |
parent | 99ed99bb5178655238add0bfc45e36c2a5686daf (diff) | |
download | rails-8067857bdfcea7bb1f916613dabfc96502932fbf.tar.gz rails-8067857bdfcea7bb1f916613dabfc96502932fbf.tar.bz2 rails-8067857bdfcea7bb1f916613dabfc96502932fbf.zip |
Merge pull request #6238 from pwnall/pgsql_bytea_limit
Postgresql doesn't accept limits on binary (bytea) columns.
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 27 | ||||
-rw-r--r-- | activerecord/test/schema/schema.rb | 1 |
2 files changed, 20 insertions, 8 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index 6714970103..14bc95abfe 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1264,14 +1264,25 @@ module ActiveRecord # Maps logical Rails types to PostgreSQL-specific data types. def type_to_sql(type, limit = nil, precision = nil, scale = nil) - return super unless type.to_s == 'integer' - return 'integer' unless limit - - case limit - when 1, 2; 'smallint' - when 3, 4; 'integer' - when 5..8; 'bigint' - else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.") + case type.to_s + when 'binary' + # PostgreSQL doesn't support limits on binary (bytea) columns. + # The hard limit is 1Gb, because of a 32-bit size field, and TOAST. + case limit + when nil, 0..0x3fffffff; super(type) + else raise(ActiveRecordError, "No binary type has byte size #{limit}.") + end + when 'integer' + return 'integer' unless limit + + case limit + when 1, 2; 'smallint' + when 3, 4; 'integer' + when 5..8; 'bigint' + else raise(ActiveRecordError, "No integer type has byte size #{limit}. Use a numeric with precision 0 instead.") + end + else + super end end diff --git a/activerecord/test/schema/schema.rb b/activerecord/test/schema/schema.rb index 3fc58c25b1..5bcb9652cd 100644 --- a/activerecord/test/schema/schema.rb +++ b/activerecord/test/schema/schema.rb @@ -80,6 +80,7 @@ ActiveRecord::Schema.define do create_table :binaries, :force => true do |t| t.string :name t.binary :data + t.binary :short_data, :limit => 2048 end create_table :birds, :force => true do |t| |