Method: Postgres#index_names

Defined in:
lib/pgcp/postgres.rb

#index_names(schema_name, table_name) ⇒ Object



169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
# File 'lib/pgcp/postgres.rb', line 169

def index_names(schema_name, table_name)
  with_connection do |conn|
    sql = <<-SQL.strip_heredoc
      SELECT
          C.relname AS "index_name"
      FROM pg_catalog.pg_class C,
           pg_catalog.pg_namespace N,
           pg_catalog.pg_index I,
           pg_catalog.pg_class C2
      WHERE C.relkind IN ( 'i', '' )
        AND N.oid = C.relnamespace
        AND N.nspname = '#{schema_name}'
        AND I.indexrelid = C.oid
        AND C2.oid = I.indrelid
        AND C2.relname = '#{table_name}';
    SQL

    rs = conn.exec sql

    rs.values.map(&:first)
  end
end