两个具有相同列名和相同索引名称的Postgres表。需要删除其中一个

时间:2018-02-18 16:41:39

标签: postgresql indexing

我有两张桌子:

x_development=# \d+ xref__email_addresses__organizations
                              Table "public.xref__email_addresses__organizations"
         Column          |            Type             |       Modifiers        | Storage | Stats target | Description 
-------------------------+-----------------------------+------------------------+---------+--------------+-------------
 email_address_id        | integer                     | not null               | plain   |              | 
 rorganization_id        | integer                     | not null               | plain   |              | 
 last_update             | timestamp without time zone | not null default now() | plain   |              | 
Indexes:
    "email_address_id_idx" UNIQUE, btree (email_address_id)
    "xref_idx" UNIQUE, btree (email_address_id, organization_id)
Foreign-key constraints:
    "email_address_id_fkey" FOREIGN KEY (email_address_id) REFERENCES email_addresses(email_address_id) ON UPDATE CASCADE ON DELETE RESTRICT
    "organization_id_fkey" FOREIGN KEY (realtor_organization_id) REFERENCES realtor_organizations(realtor_organization_id) ON UPDATE CASCADE ON DELETE RESTRICT


x_development=# \d+ email_addresses
                                                          Table "public.email_addresses"
       Column       |  Type   |                                 Modifiers                                  | Storage  | Stats target | Description 
--------------------+---------+----------------------------------------------------------------------------+----------+--------------+-------------
 email_address_id   | integer | not null default nextval('email_addresses_email_address_id_seq'::regclass) | plain    |              | 
 email_address      | citext  | not null                                                                   | extended |              | 
 unsubscribe_reason | text    | not null default ''::text                                                  | extended |              | 
Indexes:
    "email_addresses_pkey" PRIMARY KEY, btree (email_address_id)
    "email_address_idx" UNIQUE, btree (email_address)
Referenced by:
    TABLE "xref__email_addresses__organizations" CONSTRAINT "email_address_id_fkey" FOREIGN KEY (email_address_id) REFERENCES email_addresses(email_address_id) ON UPDATE CASCADE ON DELETE RESTRICT

请注意,它们都有email_address_id列和
"email_address_id_idx" UNIQUE, btree (email_address_id)索引。

我需要将email_address_id_idx放在xref__email_addresses__organizations表上,但似乎是通过使用两个相同的索引名称错误地创建了表。

如何从email_address_id_idx表中删除xref__email_addresses__organizations

1 个答案:

答案 0 :(得分:3)

据我所知,指数不同。其中一个是 email_address_id_idx ,另一个是 email_address_idx 。所以我认为您只需使用 drop index 即可删除所需的内容。