method
indexes
v3.0.9 -
Show latest stable
- Class:
ActiveRecord::ConnectionAdapters::PostgreSQLAdapter
indexes(table_name, name = nil)public
Returns the list of all indexes for a table.
# File activerecord/lib/active_record/connection_adapters/postgresql_adapter.rb, line 644
def indexes(table_name, name = nil)
schemas = schema_search_path.split(/,/).map { |p| quote(p) }.join(',')
result = query( SELECT distinct i.relname, d.indisunique, d.indkey, t.oid FROM pg_class t, pg_class i, pg_index d WHERE i.relkind = 'i' AND d.indexrelid = i.oid AND d.indisprimary = 'f' AND t.oid = d.indrelid AND t.relname = '#{table_name}' AND i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname IN (#{schemas}) ) ORDER BY i.relname, name)
result.map do |row|
index_name = row[0]
unique = row[1] == 't'
indkey = row[2].split(" ")
oid = row[3]
columns = Hash[query( SELECT a.attnum, a.attname FROM pg_attribute a WHERE a.attrelid = #{oid} AND a.attnum IN (#{indkey.join(",")}), "Columns for index #{row[0]} on #{table_name}")]
column_names = columns.values_at(*indkey).compact
column_names.empty? ? nil : IndexDefinition.new(table_name, index_name, unique, column_names)
end.compact
end Related methods
- Instance methods
- active?
- adapter_name
- add_column
- begin_db_transaction
- change_column
- change_column_default
- change_column_null
- client_min_messages
- client_min_messages=
- columns
- commit_db_transaction
- create
- create_database
- create_savepoint
- current_database
- default_sequence_name
- disable_referential_integrity
- disconnect!
- distinct
- drop_database
- encoding
- escape_bytea
- execute
- index_name_length
- indexes
- insert
- native_database_types
- outside_transaction?
- pk_and_sequence_for
- primary_key
- query
- quote
- quote_column_name
- quote_string
- quote_table_name
- quoted_date
- reconnect!
- recreate_database
- release_savepoint
- remove_index!
- rename_column
- rename_table
- reset_pk_sequence!
- result_as_array
- rollback_db_transaction
- rollback_to_savepoint
- schema_search_path
- schema_search_path=
- select_rows
- set_standard_conforming_strings
- supports_ddl_transactions?
- supports_disable_referential_integrity?
- supports_insert_with_returning?
- supports_migrations?
- supports_primary_key?
- supports_savepoints?
- table_alias_length
- table_exists?
- tables
- type_to_sql
- unescape_bytea
- update_sql
- Class methods
- new
- Protected methods
-
postgresql_version -
translate_exception - Private methods
-
column_definitions -
configure_connection -
connect -
extract_pg_identifier_from_name -
last_insert_id -
select -
select_raw