diff options
Diffstat (limited to 'activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb')
-rw-r--r-- | activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb | 40 |
1 files changed, 15 insertions, 25 deletions
diff --git a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb index da2144bee7..eacb26a254 100644 --- a/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb +++ b/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb @@ -543,7 +543,7 @@ module ActiveRecord load_additional_types(type_map, [oid]) end - type_map.fetch(normalize_oid_type(oid, fmod), sql_type) { + type_map.fetch(oid, fmod, sql_type) { warn "unknown OID #{oid}: failed to recognize type of '#{column_name}'. It will be treated as String." Type::Value.new.tap do |cast_type| type_map.register_type(oid, cast_type) @@ -551,23 +551,6 @@ module ActiveRecord } end - OID_FOR_DECIMAL_TREATED_AS_INT = 23 # :nodoc: - - def normalize_oid_type(ftype, fmod) - # The type for the numeric depends on the width of the field, - # so we'll do something special here. - # - # When dealing with decimal columns: - # - # places after decimal = fmod - 4 & 0xffff - # places before decimal = (fmod - 4) >> 16 & 0xffff - if ftype == 1700 && (fmod - 4 & 0xffff).zero? - OID_FOR_DECIMAL_TREATED_AS_INT - else - ftype - end - end - def initialize_type_map(m) register_class_with_limit m, 'int2', OID::Integer m.alias_type 'int4', 'int2' @@ -610,20 +593,27 @@ module ActiveRecord m.alias_type 'lseg', 'varchar' m.alias_type 'box', 'varchar' - m.register_type 'timestamp' do |_, sql_type| + m.register_type 'timestamp' do |_, _, sql_type| precision = extract_precision(sql_type) OID::DateTime.new(precision: precision) end - m.register_type 'numeric' do |_, sql_type| + m.register_type 'numeric' do |_, fmod, sql_type| precision = extract_precision(sql_type) scale = extract_scale(sql_type) - OID::Decimal.new(precision: precision, scale: scale) - end - m.register_type OID_FOR_DECIMAL_TREATED_AS_INT do |_, sql_type| - precision = extract_precision(sql_type) - OID::Integer.new(precision: precision) + # The type for the numeric depends on the width of the field, + # so we'll do something special here. + # + # When dealing with decimal columns: + # + # places after decimal = fmod - 4 & 0xffff + # places before decimal = (fmod - 4) >> 16 & 0xffff + if fmod && (fmod - 4 & 0xffff).zero? + Type::DecimalWithoutScale.new(precision: precision) + else + OID::Decimal.new(precision: precision, scale: scale) + end end load_additional_types(m) |