class ActiveRecord::ConnectionAdapters::PostgreSQLColumn

:nodoc:
PostgreSQL-specific extensions to column definitions in a table.

def self.extract_value_from_default(default)

Extracts the value from a PostgreSQL column default definition.
def self.extract_value_from_default(default)
  case default
    # Numeric types
    when /\A\(?(-?\d+(\.\d*)?\)?)\z/
      $1
    # Character types
    when /\A'(.*)'::(?:character varying|bpchar|text)\z/m
      $1
    # Character types (8.1 formatting)
    when /\AE'(.*)'::(?:character varying|bpchar|text)\z/m
      $1.gsub(/\\(\d\d\d)/) { $1.oct.chr }
    # Binary data types
    when /\A'(.*)'::bytea\z/m
      $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/m
      $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

def extract_limit(sql_type)

def extract_limit(sql_type)
  case sql_type
  when /^bigint/i;    8
  when /^smallint/i;  2
  else super
  end
end

def extract_precision(sql_type)

Extracts the precision from PostgreSQL-specific data types.
def extract_precision(sql_type)
  # Actual code is defined dynamically in PostgreSQLAdapter.connect
  # depending on the server specifics
  super
end

def extract_scale(sql_type)

Extracts the scale from PostgreSQL-specific data types.
def extract_scale(sql_type)
  # Money type has a fixed scale of 2.
  sql_type =~ /^money/ ? 2 : super
end

def initialize(name, default, sql_type = nil, null = true)

Instantiates a new PostgreSQL column definition in a table.
:nodoc:
PostgreSQL-specific extensions to column definitions in a table.
def initialize(name, default, sql_type = nil, null = true)
  super(name, self.class.extract_value_from_default(default), sql_type, null)
end

def simplified_type(field_type)

Maps PostgreSQL-specific data types to logical Rails types.
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
    # Arrays
    when /^\D+\[\]$/
      :string
    # Object identifier types
    when /^oid$/
      :integer
    # Pass through all types that are not specific to PostgreSQL.
    else
      super
  end
end