Re: Check for existence of index - Mailing list pgsql-general

From Tom Lane
Subject Re: Check for existence of index
Date
Msg-id 26226.1112725195@sss.pgh.pa.us
Whole thread Raw
In response to Re: Check for existence of index  (David Rysdam <drysdam@ll.mit.edu>)
Responses Re: Check for existence of index  (David Rysdam <drysdam@ll.mit.edu>)
List pgsql-general
David Rysdam <drysdam@ll.mit.edu> writes:
> Why can't I have the same index name be on
> different tables?

You can ... if they are in different schemas.  Indexes and tables share
the same namespace, ie, they must be unique within a schema.

As for your original question, you probably want something like

SELECT ... FROM pg_class c, pg_namespace n WHERE c.relnamespace = n.oid
  AND relname = 'indexname' AND nspname = 'schemaname' AND relkind = 'i';

If you actually want to verify that this index is on a specific table,
you'll need a more complicated join involving pg_index and a second
scan of pg_class.  See
http://www.postgresql.org/docs/8.0/static/catalogs.html

            regards, tom lane

pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: change attnum in pg_catalog.pg_attribute
Next
From: Grzegorz Przeździecki
Date:
Subject: Re: change attnum in pg_catalog.pg_attribute