diff options
author | Victor Costan <costan@gmail.com> | 2012-05-09 23:38:24 -0400 |
---|---|---|
committer | Victor Costan <costan@gmail.com> | 2012-05-21 03:21:32 -0400 |
commit | 36fdb728c63f9788c4c646a00c73933f59165789 (patch) | |
tree | dd3861508c89d2461ddbf6727887d3c8b961c883 /activerecord/lib | |
parent | b0f8355d2813c375bf9242071131e8c5a350bcf0 (diff) | |
download | rails-36fdb728c63f9788c4c646a00c73933f59165789.tar.gz rails-36fdb728c63f9788c4c646a00c73933f59165789.tar.bz2 rails-36fdb728c63f9788c4c646a00c73933f59165789.zip |
Postgresql doesn't accept limits on binary (bytea) columns.
Diffstat (limited to 'activerecord/lib')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 27 |
1 files changed, 19 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 7aa7f1ebcf..2d1517b65e 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -1067,14 +1067,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 |