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

The PostgreSQL adapter works both with the native C (ruby.scripting.ca/postgres/) and the pure Ruby (available both as gem and from rubyforge.org/frs/?group_id=234&release_id=1944) 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 used in a SET client_encoding TO <encoding> call on the connection.
  • :min_messages - An optional client min messages that is used in a SET client_min_messages TO <min_messages> call on the connection.

Methods

Classes and Modules

Module ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::Utils
Class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::StatementPool
Class ActiveRecord::ConnectionAdapters::PostgreSQLAdapter::TableDefinition

Constants

ADAPTER_NAME = 'PostgreSQL'
NATIVE_DATABASE_TYPES = { :primary_key => "serial primary key", :string => { :name => "character varying", :limit => 255 }, :text => { :name => "text" }, :integer => { :name => "integer" }, :float => { :name => "float" }, :decimal => { :name => "decimal" }, :datetime => { :name => "timestamp" }, :timestamp => { :name => "timestamp" }, :time => { :name => "time" }, :date => { :name => "date" }, :binary => { :name => "bytea" }, :boolean => { :name => "boolean" }, :xml => { :name => "xml" }, :tsvector => { :name => "tsvector" }

External Aliases

insert -> create

Public Class methods

Initializes and connects a PostgreSQL adapter.

Public Instance methods

Is this connection alive and ready for queries?

Returns ‘PostgreSQL’ as adapter name for identification purposes.

Adds a new column to the named table. See TableDefinition#column for details of the options you can use.

Begins a transaction.

Changes the default value of a table column.

Clears the prepared statements cache.

Returns the current client message level.

Set the client message level.

Returns the list of all column definitions for a table.

Commits a transaction.

Create a new PostgreSQL database. Options include :owner, :template, :encoding, :tablespace, and :connection_limit (note that MySQL uses :charset while PostgreSQL uses :encoding).

Example:

  create_database config[:database], config
  create_database 'foo_development', :encoding => 'unicode'

Returns the current database name.

Returns the current schema name.

Disconnects from the database if already connected. Otherwise, this method does nothing.

Returns the current database encoding format.

Escapes binary strings for bytea input to the database.

exec_update(sql, name = 'SQL', binds = [])

Alias for exec_delete

Executes an SQL statement, returning a PGresult object on success or raising a PGError exception otherwise.

DATABASE STATEMENTS ======================================

Returns an array of indexes for the given table.

Executes an INSERT query and returns the new record‘s ID

Returns just a table‘s primary key

Checks the following cases:

  • table_name
  • "table.name"
  • schema_name.table_name
  • schema_name."table.name"
  • "schema.name".table_name
  • "schema.name"."table.name"

Close then reopen the connection.

Renames a table.

Example:

  rename_table('octopuses', 'octopi')

Aborts a transaction.

Returns true if schema exists.

Returns the active schema search path.

Sets the schema search path to a string of comma-separated schema names. Names beginning with $ have to be quoted (e.g. $user => ’$user’). See: www.postgresql.org/docs/current/static/ddl-schemas.html

This should be not be called manually but set in database.yml.

Executes a SELECT query and returns an array of rows. Each row is an array of field values.

Set the authorized user for this session

Enable standard-conforming strings if available.

Returns true.

Returns true, since this connection adapter supports migrations.

Returns true, since this connection adapter supports savepoints.

Returns true, since this connection adapter supports prepared statement caching.

Returns the configured supported identifier length supported by PostgreSQL

Returns true if table exists. If the schema is not specified as part of name then it will only find tables within the current schema search path (regardless of permissions to access tables in other schemas)

Returns the list of all tables in the schema search path or a specified schema.

Maps logical Rails types to PostgreSQL-specific data types.

Unescapes bytea output from a database to the binary string it represents. NOTE: This is NOT an inverse of escape_bytea! This is only to be used

      on escaped binary output from database drive.

Executes an UPDATE query and returns the number of affected tuples.

Protected Instance methods

Returns the version of the connected PostgreSQL server.

[Validate]