0

below query works perfectly in postgre, because duplicate index within table is not allowed but with in DB it is allowed.

sandbox=# create schema test;
CREATE SCHEMA
sandbox=# create table public.a (a_id integer not null);
CREATE TABLE
sandbox=# create table test.a (a_id integer not null);
CREATE TABLE
sandbox=# create index a_idx on public.a (a_id);
CREATE INDEX
sandbox=# create index a_idx on test.a (a_id);
CREATE INDEX

what happens when I do

DROP INDEX a_idx;
  1. will both the indexes get deleted ?
  2. can I write DROP INDEX test.a.a_idx ?
  3. how the index look up works while deleting ?

2 Answers 2

1

What happens depends on the setting of search_path. PostgreSQL searches the existing schemas on search_path in turn, and as soon as it finds an index of that name, it drops the index and is done.

Sign up to request clarification or add additional context in comments.

Comments

0

can I write DROP INDEX test.a.a_idx ?

The index is in the same schema as its table, so it would just be DROP INDEX test.a_idx (if you want/need to override search_path)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.