method
indexes
v2.2.1 -
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 637
def indexes(table_name, name = nil)
schemas = schema_search_path.split(/,/).map { |p| quote(p) }.join(',')
result = query("SELECT distinct 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 i.relnamespace IN (SELECT oid FROM pg_namespace WHERE nspname IN (\#{schemas}) )\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
- add_order_by_for_association_limiting!
- begin_db_transaction
- change_column
- change_column_default
- change_column_null
- client_min_messages
- client_min_messages=
- columns
- commit_db_transaction
- create_database
- current_database
- default_sequence_name
- disable_referential_integrity
- disconnect!
- distinct
- drop_database
- encoding
- escape_bytea
- execute
- indexes
- insert
- native_database_types
- pk_and_sequence_for
- query
- quote
- quote_column_name
- quote_string
- quoted_date
- reconnect!
- recreate_database
- remove_index
- rename_column
- rename_table
- reset_pk_sequence!
- result_as_array
- rollback_db_transaction
- schema_search_path
- schema_search_path=
- select_rows
- supports_ddl_transactions?
- supports_disable_referential_integrity?
- supports_insert_with_returning?
- supports_migrations?
- supports_standard_conforming_strings?
- table_alias_length
- tables
- transaction
- transaction_active?
- type_to_sql
- unescape_bytea
- update_sql
- Class methods
- new
- Protected methods
-
postgresql_version - Private methods
-
column_definitions -
configure_connection -
connect -
last_insert_id -
select -
select_raw