def indexes(table_name, name = nil)
       schemas = schema_search_path.split(/,/).map { |p| quote(p) }.join(',')

       # Changed from upstread: link to pg_am to grab the index type (e.g. "gist")
       result = query(<<-SQL, name)
         SELECT distinct i.relname, d.indisunique, d.indkey, t.oid, am.amname
           FROM pg_class t, pg_class i, pg_index d, pg_attribute a, pg_am am
         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}) )
           AND i.relam = am.oid
           AND a.attrelid = t.oid
        ORDER BY i.relname
      SQL


      indexes = []

      indexes = result.map do |row|
        index_name = row[0]
        unique = row[1] == 't'
        indkey = row[2].split(" ")
        oid = row[3]
        indtype = row[4]

        # Changed from upstream: need to get the column types to test for spatial indexes
        columns = query(<<-SQL, "Columns for index #{row[0]} on #{table_name}").inject({}) {|attlist, r| attlist[r[1]] = [r[0], r[2]]; attlist}
        SELECT a.attname, a.attnum, t.typname
        FROM pg_attribute a, pg_type t
        WHERE a.attrelid = #{oid}
        AND a.attnum IN (#{indkey.join(",")})
        AND a.atttypid = t.oid
        SQL

        # Only GiST indexes on spatial columns denote a spatial index
        spatial = indtype == 'gist' && columns.size == 1 && (columns.values.first[1] == 'geometry' || columns.values.first[1] == 'geography')

        column_names = indkey.map {|attnum| columns[attnum] ? columns[attnum][0] : nil }
        ActiveRecord::ConnectionAdapters::IndexDefinition.new(table_name, index_name, unique, column_names, spatial)
      end

      indexes
    end
def indexes(table_name, name = nil)
       schemas = schema_search_path.split(/,/).map { |p| quote(p) }.join(',')

       # Changed from upstread: link to pg_am to grab the index type (e.g. "gist")
       result = query(<<-SQL, name)
         SELECT distinct i.relname, d.indisunique, d.indkey, t.oid, am.amname
           FROM pg_class t, pg_class i, pg_index d, pg_attribute a, pg_am am
         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}) )
           AND i.relam = am.oid
           AND a.attrelid = t.oid
        ORDER BY i.relname
      SQL


      indexes = []

      indexes = result.map do |row|
        index_name = row[0]
        unique = row[1] == 't'
        indkey = row[2].split(" ")
        oid = row[3]
        indtype = row[4]

        # Changed from upstream: need to get the column types to test for spatial indexes
        columns = query(<<-SQL, "Columns for index #{row[0]} on #{table_name}").inject({}) {|attlist, r| attlist[r[1]] = [r[0], r[2]]; attlist}
        SELECT a.attname, a.attnum, t.typname
        FROM pg_attribute a, pg_type t
        WHERE a.attrelid = #{oid}
        AND a.attnum IN (#{indkey.join(",")})
        AND a.atttypid = t.oid
        SQL

        # Only GiST indexes on spatial columns denote a spatial index
        spatial = indtype == 'gist' && columns.size == 1 && (columns.values.first[1] == 'geometry' || columns.values.first[1] == 'geography')

        column_names = indkey.map {|attnum| columns[attnum] ? columns[attnum][0] : nil }
        ActiveRecord::ConnectionAdapters::IndexDefinition.new(table_name, index_name, unique, column_names, spatial)
      end

      indexes
    end
Returns the list of all indexes for a table.

 This is a full replacement for the ActiveRecord method and as a result
 has a higher probability of breaking in future releases.