Skip to content

Commit

Permalink
handle atttypmod being correct for decimals from v22.1
Browse files Browse the repository at this point in the history
  • Loading branch information
otan committed Feb 2, 2022
1 parent 64bd3ee commit 7f0ede7
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/active_record/connection_adapters/cockroachdb_adapter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,19 @@ def initialize_type_map(m = type_map)
precision = extract_precision(sql_type)
scale = extract_scale(sql_type)


# 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
#
# For older versions of CockroachDB (<v22.1), fmod is -1 for 0 width.
# If fmod is -1, that means that precision is defined but not
# scale, or neither is defined.
if fmod && fmod == -1 && !precision.nil?
if fmod && ((fmod == -1 && !precision.nil?) || (fmod - 4 & 0xffff).zero?)
# Below comment is from ActiveRecord
# FIXME: Remove this class, and the second argument to
# lookups on PG
Expand Down

0 comments on commit 7f0ede7

Please sign in to comment.