PostgreSQL-specific extensions to column definitions in a table.
Extracts the value from a PostgreSQL column default definition.
# File lib/active_record/connection_adapters/postgresql_adapter.rb, line 124
124: def self.extract_value_from_default(default)
125: case default
126: # Numeric types
127: when /\A\(?(-?\d+(\.\d*)?\)?)\z/
128: $1
129: # Character types
130: when /\A'(.*)'::(?:character varying|bpchar|text)\z/
131: $1
132: # Character types (8.1 formatting)
133: when /\AE'(.*)'::(?:character varying|bpchar|text)\z/
134: $1.gsub(/\\(\d\d\d)/) { $1.oct.chr }
135: # Binary data types
136: when /\A'(.*)'::bytea\z/
137: $1
138: # Date/time types
139: when /\A'(.+)'::(?:time(?:stamp)? with(?:out)? time zone|date)\z/
140: $1
141: when /\A'(.*)'::interval\z/
142: $1
143: # Boolean type
144: when 'true'
145: true
146: when 'false'
147: false
148: # Geometric types
149: when /\A'(.*)'::(?:point|line|lseg|box|"?path"?|polygon|circle)\z/
150: $1
151: # Network address types
152: when /\A'(.*)'::(?:cidr|inet|macaddr)\z/
153: $1
154: # Bit string types
155: when /\AB'(.*)'::"?bit(?: varying)?"?\z/
156: $1
157: # XML type
158: when /\A'(.*)'::xml\z/
159: $1
160: # Arrays
161: when /\A'(.*)'::"?\D+"?\[\]\z/
162: $1
163: # Object identifier types
164: when /\A-?\d+\z/
165: $1
166: else
167: # Anything else is blank, some user type, or some function
168: # and we can't know the value of that, so return nil.
169: nil
170: end
171: end
# File lib/active_record/connection_adapters/postgresql_adapter.rb, line 50
50: def extract_limit(sql_type)
51: case sql_type
52: when /^bigint/; 8
53: when /^smallint/; 2
54: else super
55: end
56: end
Extracts the precision from PostgreSQL-specific data types.
# File lib/active_record/connection_adapters/postgresql_adapter.rb, line 65
65: def extract_precision(sql_type)
66: if sql_type == 'money'
67: self.class.money_precision
68: else
69: super
70: end
71: end
Extracts the scale from PostgreSQL-specific data types.
# File lib/active_record/connection_adapters/postgresql_adapter.rb, line 59
59: def extract_scale(sql_type)
60: # Money type has a fixed scale of 2.
61: sql_type =~ /^money/ ? 2 : super
62: end
Maps PostgreSQL-specific data types to logical Rails types.
# File lib/active_record/connection_adapters/postgresql_adapter.rb, line 74
74: def simplified_type(field_type)
75: case field_type
76: # Numeric and monetary types
77: when /^(?:real|double precision)$/
78: :float
79: # Monetary types
80: when 'money'
81: :decimal
82: # Character types
83: when /^(?:character varying|bpchar)(?:\(\d+\))?$/
84: :string
85: # Binary data types
86: when 'bytea'
87: :binary
88: # Date/time types
89: when /^timestamp with(?:out)? time zone$/
90: :datetime
91: when 'interval'
92: :string
93: # Geometric types
94: when /^(?:point|line|lseg|box|"?path"?|polygon|circle)$/
95: :string
96: # Network address types
97: when /^(?:cidr|inet|macaddr)$/
98: :string
99: # Bit strings
100: when /^bit(?: varying)?(?:\(\d+\))?$/
101: :string
102: # XML type
103: when 'xml'
104: :xml
105: # Arrays
106: when /^\D+\[\]$/
107: :string
108: # Object identifier types
109: when 'oid'
110: :integer
111: # UUID type
112: when 'uuid'
113: :string
114: # Small and big integer types
115: when /^(?:small|big)int$/
116: :integer
117: # Pass through all types that are not specific to PostgreSQL.
118: else
119: super
120: end
121: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.