检查PostgreSQL中是否存在索引
发布时间:2020-12-13 15:49:49 所属栏目:百科 来源:网络整理
导读:参见英文答案 CREATE UNIQUE INDEX IF NOT EXISTS in postgreSQL????????????????????????????????????6个 我知道如何创建索引 CREATE INDEX ix_dsvtable ON public."DsVTable" USING btree (dind,sec,regind,datind); 如何检查索引是否已存在? 如果它们还
参见英文答案 >
CREATE UNIQUE INDEX IF NOT EXISTS in postgreSQL????????????????????????????????????6个
我知道如何创建索引 CREATE INDEX ix_dsvtable ON public."DsVTable" USING btree (dind,sec,regind,datind); 如何检查索引是否已存在? 如果它们还不存在,我需要检查它们的存在并创建它们. 解决方法
您可以使用以下查询获取索引列表,其表和列:
select t.relname as table_name,i.relname as index_name,a.attname as column_name from pg_class t,pg_class i,pg_index ix,pg_attribute a where t.oid = ix.indrelid and i.oid = ix.indexrelid and a.attrelid = t.oid and a.attnum = ANY(ix.indkey) and t.relkind = 'r' -- and t.relname like 'mytable' order by t.relname,i.relname; 从那里,您可以通过索引名称或涉及的列检查存在,并决定创建/跳过索引. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |