PostgreSQL 9.6. 删除索引出现问题

19

在一个旧版的PostgreSQL数据库中,我尝试使用以下命令删除一个已存在的索引:

DROP INDEX index_name;

However, I got an error message saying that the index does not exist. What am I doing wrong?

DROP INDEX testing.idx_testing_data_model_output_data_id;

并查看错误:

ERROR:  index "<index name>" does not exist

但我可以使用\d <table name>命令来查看索引:


leg=# \d testing.data_model
                                           Table "testing.data_model"
     Column     |            Type             |                                 Modifiers
----------------+-----------------------------+---------------------------------------------------------------------------
 id             | bigint                      | not null default nextval('testing.data_model_id_seq'::regclass) 
 input_data     | text                        | 
 output_data_id | bigint                      | 
Indexes:
    "pk_testing_data_model" PRIMARY KEY, btree (id)
    "idx_testing_data_model_output_data_id" btree (output_data_id)

好的,当我尝试创建索引时,出现了以下错误:

ERROR:  relation "<index name>" already exists

看起来索引的创建或删除并没有成功完成。我该如何解决这个问题?


1
这里是内容,但尝试更好地格式化。 - user1053031
3
你要使用的确切命令是什么来删除索引? - user330315
4
我使用了“drop index <schema_name>.<index_name as is from \d cmd>”命令。 - user1053031
4
如果你像那样包含了引号,那就有问题了。它必须是"testing"."idx_testing_data_model_output_data_id"- 名称的每个元素必须单独加引号。 - user330315
2
谢谢您的建议,但我可以完全不使用引号删除其他索引,例如“DROP INDEX schema.idx_factor_log_id;”。 - user1053031
显示剩余8条评论
1个回答

9
SET search_path = <schema_name>;

设置 search_path 对我很有用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接