Class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
In: vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb
Parent: AbstractAdapter

The PostgreSQL adapter works both with the C-based (www.postgresql.jp/interfaces/ruby/) and the Ruby-base (available both as gem and from rubyforge.org/frs/?group_id=234&release_id=1145) drivers.

Options:

  • :host — Defaults to localhost
  • :port — Defaults to 5432
  • :username — Defaults to nothing
  • :password — Defaults to nothing
  • :database — The name of the database. No default, must be provided.
  • :schema_search_path — An optional schema search path for the connection given as a string of comma-separated schema names. This is backward-compatible with the :schema_order option.
  • :encoding — An optional client encoding that is using in a SET client_encoding TO <encoding> call on connection.
  • :min_messages — An optional client min messages that is using in a SET client_min_messages TO <min_messages> call on connection.

Methods

Constants

BYTEA_COLUMN_TYPE_OID = 17

Public Instance methods

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 134
134:       def adapter_name
135:         'PostgreSQL'
136:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 118
118:       def begin_db_transaction()    execute "BEGIN" end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 153
153:       def change_column(table_name, column_name, type, options = {})
154:         execute = "ALTER TABLE #{table_name} ALTER  #{column_name} TYPE #{type}"
155:         change_column_default(table_name, column_name, options[:default]) unless options[:default].nil?
156:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 158
158:       def change_column_default(table_name, column_name, default)
159:         execute "ALTER TABLE #{table_name} ALTER COLUMN #{column_name} SET DEFAULT '#{default}'"
160:       end

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 92
92:       def columns(table_name, name = nil)
93:         column_definitions(table_name).collect do |name, type, default|
94:           Column.new(name, default_value(default), translate_field_type(type))
95:         end
96:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 119
119:       def commit_db_transaction()   execute "COMMIT" end
delete(sql, name = nil)

Alias for update

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 108
108:       def execute(sql, name = nil)
109:         log(sql, name) { @connection.exec(sql) }
110:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 98
 98:       def insert(sql, name = nil, pk = nil, id_value = nil)
 99:         execute(sql, name)
100:         table = sql.split(" ", 4)[2]
101:         return id_value || last_insert_id(table, pk)
102:       end

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 63
63:       def native_database_types
64:         {
65:           :primary_key => "serial primary key",
66:           :string      => { :name => "character varying", :limit => 255 },
67:           :text        => { :name => "text" },
68:           :integer     => { :name => "integer" },
69:           :float       => { :name => "float" },
70:           :datetime    => { :name => "timestamp" },
71:           :timestamp   => { :name => "timestamp" },
72:           :time        => { :name => "timestamp" },
73:           :date        => { :name => "date" },
74:           :binary      => { :name => "bytea" },
75:           :boolean     => { :name => "boolean"}
76:         }
77:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 104
104:       def query(sql, name = nil)
105:         log(sql, name) { @connection.query(sql) }
106:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 122
122:       def quote(value, column = nil)
123:         if value.class == String && column && column.type == :binary
124:           quote_bytea(value)
125:         else
126:           super
127:         end
128:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 130
130:       def quote_column_name(name)
131:         %("#{name}")
132:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 166
166:       def remove_index(table_name, column_name)
167:         execute "DROP INDEX #{table_name}_#{column_name}_index"
168:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 162
162:       def rename_column(table_name, column_name, new_column_name)
163:         execute "ALTER TABLE #{table_name} RENAME COLUMN #{column_name} TO #{new_column_name}"
164:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 120
120:       def rollback_db_transaction() execute "ROLLBACK" end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 149
149:       def schema_search_path
150:         @schema_search_path ||= query('SHOW search_path')[0][0]
151:       end

Set the schema search path to a string of comma-separated schema names. Names beginning with $ are quoted (e.g. $user => ’$user’) See www.postgresql.org/docs/8.0/interactive/ddl-schemas.html

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 142
142:       def schema_search_path=(schema_csv)
143:         if schema_csv
144:           execute "SET search_path TO #{schema_csv}"
145:           @schema_search_path = nil
146:         end
147:       end

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 83
83:       def select_all(sql, name = nil)
84:         select(sql, name)
85:       end

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 87
87:       def select_one(sql, name = nil)
88:         result = select(sql, name)
89:         result.nil? ? nil : result.first
90:       end

[Source]

    # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 79
79:       def supports_migrations?
80:         true
81:       end

[Source]

     # File vendor/rails/activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 112
112:       def update(sql, name = nil)
113:         execute(sql, name).cmdtuples
114:       end

[Validate]