Re: ALTER INDEX .. RENAME allows to rename tables/views as well

From: Bruce Momjian <bruce(at)momjian(dot)us>
To: Onder Kalaci <onderk(at)microsoft(dot)com>
Cc: "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org>
Subject: Re: ALTER INDEX .. RENAME allows to rename tables/views as well
Date: 2021-10-06 20:51:57
Message-ID: 20211006205157.GG20296@momjian.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers


I can confirm this bug in git head, and I think it should be fixed.

---------------------------------------------------------------------------

On Mon, Oct 4, 2021 at 10:23:23AM +0000, Onder Kalaci wrote:
> Hi hackers,
>
> I realized a subtle behavior with ALTER INDEX .. RENAME. It seems like a bug to
> me, please see the steps below.
>
>
>
> Test 1: Rename table via RENAME .. INDEX
>
> CREATE TABLE test_table (a int);
>
> SELECT 'test_table'::regclass::oid;
>
> oid
>
> -------
>
> 34470
>
> (1 row)
>
> -- rename table using ALTER INDEX ..
>
> ALTER INDEX test_table RENAME TO test_table_2;
>
>
> -- see that table is rename
>
> SELECT 34470::regclass;
>
> regclass
>
> --------------
>
> test_table_2
>
> (1 row)
>
>
> Test 2: Rename view via RENAME .. INDEX
> CREATE VIEW test_view AS SELECT * FROM pg_class;
>
> SELECT 'test_view'::regclass::oid;
>
> oid
>
> -------
>
> 34473
>
> (1 row)
>
>
>
> ALTER INDEX test_view RENAME TO test_view_2;
>
> ELECT 34473::regclass;
>
> regclass
>
> -------------
>
> test_view_2
>
> (1 row)
>
>
>
>
> It seems like an oversight in ExecRenameStmt(), and probably applies to
> sequences, mat. views and foreign tables as well.
>
>
>
> I can reproduce this on both 13.2 and 14.0. Though haven’t checked earlier
> versions.
>
>
>
> Thanks,
>
> Onder
>

--
Bruce Momjian <bruce(at)momjian(dot)us> https://momjian.us
EDB https://enterprisedb.com

If only the physical world exists, free will is an illusion.

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zhihong Yu 2021-10-06 21:03:02 Re: using extended statistics to improve join estimates
Previous Message Peter Geoghegan 2021-10-06 20:49:12 Re: BUG #17212: pg_amcheck fails on checking temporary relations