method
indexes
v2.0.3 -
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 450
def indexes(table_name, name = nil)
result = query("SELECT i.relname, d.indisunique, a.attname\nFROM pg_class t, pg_class i, pg_index d, pg_attribute a\nWHERE i.relkind = 'i'\nAND d.indexrelid = i.oid\nAND d.indisprimary = 'f'\nAND t.oid = d.indrelid\nAND t.relname = '\#{table_name}'\nAND a.attrelid = t.oid\nAND ( d.indkey[0]=a.attnum OR d.indkey[1]=a.attnum\nOR d.indkey[2]=a.attnum OR d.indkey[3]=a.attnum\nOR d.indkey[4]=a.attnum OR d.indkey[5]=a.attnum\nOR d.indkey[6]=a.attnum OR d.indkey[7]=a.attnum\nOR d.indkey[8]=a.attnum OR d.indkey[9]=a.attnum )\nORDER BY i.relname\n", name)
current_index = nil
indexes = []
result.each do |row|
if current_index != row[0]
indexes << IndexDefinition.new(table_name, row[0], row[1] == "t", [])
current_index = row[0]
end
indexes.last.columns << row[2]
end
indexes
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
- disconnect!
- execute
- indexes
- insert
- reconnect!
- remove_index
- rename_column
- rename_table
- rollback_db_transaction
- schema_search_path
- schema_search_path=
- select_rows
- supports_migrations?
- supports_standard_conforming_strings?
- table_alias_length
- tables
- type_to_sql
- update_sql
- Class methods
- new
- Protected methods
-
postgresql_version - Private methods
-
configure_connection -
connect -
select -
select_raw