class ActiveRecord::ConnectionAdapters::PostgreSQLColumn

Private Class Methods

extract_value_from_default(default) click to toggle source

Extracts the value from a PostgreSQL column default definition.

# File lib/active_record/connection_adapters/postgresql_adapter.rb, line 134
def self.extract_value_from_default(default)
  case default
    # This is a performance optimization for Ruby 1.9.2 in development.
    # If the value is nil, we return nil straight away without checking
    # the regular expressions. If we check each regular expression,
    # Regexp#=== will call NilClass#to_str, which will trigger
    # method_missing (defined by whiny nil in ActiveSupport) which
    # makes this method very very slow.
    when NilClass
      nil
    # Numeric types
    when /\A\(?(-?\d+(\.\d*)?\)?)\z/
      $1
    # Character types
    when /\A\(?'(.*)'::.*\b(?:character varying|bpchar|text)\z/
      $1
    # Binary data types
    when /\A'(.*)'::bytea\z/
      $1
    # Date/time types
    when /\A'(.+)'::(?:time(?:stamp)? with(?:out)? time zone|date)\z/
      $1
    when /\A'(.*)'::interval\z/
      $1
    # Boolean type
    when 'true'
      true
    when 'false'
      false
    # Geometric types
    when /\A'(.*)'::(?:point|line|lseg|box|"?path"?|polygon|circle)\z/
      $1
    # Network address types
    when /\A'(.*)'::(?:cidr|inet|macaddr)\z/
      $1
    # Bit string types
    when /\AB'(.*)'::"?bit(?: varying)?"?\z/
      $1
    # XML type
    when /\A'(.*)'::xml\z/
      $1
    # Arrays
    when /\A'(.*)'::"?\D+"?\[\]\z/
      $1
    # Object identifier types
    when /\A-?\d+\z/
      $1
    else
      # Anything else is blank, some user type, or some function
      # and we can't know the value of that, so return nil.
      nil
  end
end

Private Instance Methods

extract_limit(sql_type) click to toggle source
Calls superclass method
# File lib/active_record/connection_adapters/postgresql_adapter.rb, line 57
def extract_limit(sql_type)
  case sql_type
  when /^bigint/;    8
  when /^smallint/;  2
  else super
  end
end
extract_precision(sql_type) click to toggle source

Extracts the precision from PostgreSQL-specific data types.

Calls superclass method
# File lib/active_record/connection_adapters/postgresql_adapter.rb, line 72
def extract_precision(sql_type)
  if sql_type == 'money'
    self.class.money_precision
  else
    super
  end
end
extract_scale(sql_type) click to toggle source

Extracts the scale from PostgreSQL-specific data types.

Calls superclass method
# File lib/active_record/connection_adapters/postgresql_adapter.rb, line 66
def extract_scale(sql_type)
  # Money type has a fixed scale of 2.
  sql_type =~ /^money/ ? 2 : super
end
simplified_type(field_type) click to toggle source

Maps PostgreSQL-specific data types to logical Rails types.

Calls superclass method
# File lib/active_record/connection_adapters/postgresql_adapter.rb, line 81
def simplified_type(field_type)
  case field_type
    # Numeric and monetary types
    when /^(?:real|double precision)$/
      :float
    # Monetary types
    when 'money'
      :decimal
    # Character types
    when /^(?:character varying|bpchar)(?:\(\d+\))?$/
      :string
    # Binary data types
    when 'bytea'
      :binary
    # Date/time types
    when /^timestamp with(?:out)? time zone$/
      :datetime
    when 'interval'
      :string
    # Geometric types
    when /^(?:point|line|lseg|box|"?path"?|polygon|circle)$/
      :string
    # Network address types
    when /^(?:cidr|inet|macaddr)$/
      :string
    # Bit strings
    when /^bit(?: varying)?(?:\(\d+\))?$/
      :string
    # XML type
    when 'xml'
      :xml
    # tsvector type
    when 'tsvector'
      :tsvector
    # Arrays
    when /^\D+\[\]$/
      :string
    # Object identifier types
    when 'oid'
      :integer
    # UUID type
    when 'uuid'
      :string
    # Small and big integer types
    when /^(?:small|big)int$/
      :integer
    # Pass through all types that are not specific to PostgreSQL.
    else
      super
  end
end