检查PostgreSQL中是否存在索引

前端之家收集整理的这篇文章主要介绍了检查PostgreSQL中是否存在索引前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
参见英文答案 > CREATE UNIQUE INDEX IF NOT EXISTS in postgreSQL                                    6个
我知道如何创建索引

  1. CREATE INDEX ix_dsvtable
  2. ON public."DsVTable"
  3. USING btree
  4. (dind,sec,regind,datind);

如何检查索引是否已存在?

如果它们还不存在,我需要检查它们的存在并创建它们.

解决方法

您可以使用以下查询获取索引列表,其表和列:

  1. select
  2. t.relname as table_name,i.relname as index_name,a.attname as column_name
  3. from
  4. pg_class t,pg_class i,pg_index ix,pg_attribute a
  5. where
  6. t.oid = ix.indrelid
  7. and i.oid = ix.indexrelid
  8. and a.attrelid = t.oid
  9. and a.attnum = ANY(ix.indkey)
  10. and t.relkind = 'r'
  11. -- and t.relname like 'mytable'
  12. order by
  13. t.relname,i.relname;

从那里,您可以通过索引名称或涉及的列检查存在,并决定创建/跳过索引.

猜你在找的Postgre SQL相关文章