lib/arjdbc/postgresql/column.rb
# Extracts the value from a PostgreSQL column default definition.
#
# @override JdbcColumn#default_value
# NOTE: based on `self.extract_value_from_default(default)` code
Extracts the value from a PostgreSQL column default definition.
Extracts the value from a PostgreSQL column default definition .
def default_value(default)
        return default unless default
        case default
          when /\A'(.*)'::(num|date|tstz|ts|int4|int8)range\z/m
            $1
          when /\A\(?(-?\d+(\.\d*)?\)?)\z/
            $1
          when /\A\(?'(.*)'::.*\b(?:character varying|bpchar|text)\z/m
            $1
          when /\A'(.*)'::bytea\z/m
            $1
          when /\A'(.+)'::(?:time(?:stamp)? with(?:out)? time zone|date)\z/
            $1
          when /\A'(.*)'::interval\z/
            $1
          when 'true'
            true
          when 'false'
            false
          when /\A'(.*)'::(?:point|line|lseg|box|"?path"?|polygon|circle)\z/
            $1
          when /\A'(.*)'::(?:cidr|inet|macaddr)\z/
            $1
          when /\AB'(.*)'::"?bit(?: varying)?"?\z/
            $1
          when /\A'(.*)'::xml\z/m
            $1
          when /\A'(.*)'::"?\D+"?\[\]\z/
            $1
          when /\AARRAY\[(.*)\](::\D+)?\z/
            "{#{$1.gsub(/'(.*?)'::[a-z]+(,)?\s?/, '\1\2')}}"
          when /\A'(.*)'::hstore\z/
            $1
          when /\A'(.*)'::json\z/
            $1
          when /\A-?\d+\z/
            $1
          else
            nil
        end
      end
def default_value ( default ) return default unless default case default when / \A '(.*)'::(num|date|tstz|ts|int4|int8)range \z /m $1 when / \A \( ?(-? \d +( \. \d *)? \) ?) \z / $1 when / \A \( ?'(.*)'::.* \b (?:character varying|bpchar|text) \z /m $1 when / \A '(.*)'::bytea \z /m $1 when / \A '(.+)'::(?:time(?:stamp)? with(?:out)? time zone|date) \z / $1 when / \A '(.*)'::interval \z / $1 when 'true' true when 'false' false when / \A '(.*)'::(?:point|line|lseg|box|"?path"?|polygon|circle) \z / $1 when / \A '(.*)'::(?:cidr|inet|macaddr) \z / $1 when / \A B'(.*)'::"?bit(?: varying)?"? \z / $1 when / \A '(.*)'::xml \z /m $1 when / \A '(.*)'::"? \D +"? \[ \] \z / $1 when / \A ARRAY \[ (.*) \] (:: \D +)? \z / "{#{$1.gsub(/'(.*?)'::[a-z]+(,)?\s?/, '\1\2')}}" when / \A '(.*)'::hstore \z / $1 when / \A '(.*)'::json \z / $1 when / \A -? \d + \z / $1 else nil end end
Extracts the value from a PostgreSQL column default definition.
Extracts the value from a PostgreSQL column default definition .
# 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. # Numeric types # Character types # Binary data types # Date/time types # Boolean type # Geometric types # Network address types # Bit string types # XML type # Arrays # Hstore # JSON # Object identifier types # Anything else is blank, some user type, or some function # and we can't know the value of that, so return nil.
default
override
JdbcColumn#default_value NOTE: based on `self.extract_value_from_default(default)` code
JdbcColumn#default_value NOTE : based on ` self . extract_value_from_default ( default ) ` code