ALTER INDEX .. RENAME allows to rename tables/views as well - Mailing list pgsql-hackers

From Onder Kalaci
Subject ALTER INDEX .. RENAME allows to rename tables/views as well
Date
Msg-id PH0PR21MB1328189E2821CDEC646F8178D8AE9@PH0PR21MB1328.namprd21.prod.outlook.com
Whole thread Raw
Responses Re: ALTER INDEX .. RENAME allows to rename tables/views as well  (Bruce Momjian <bruce@momjian.us>)
List pgsql-hackers

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

pgsql-hackers by date:

Previous
From: Laurenz Albe
Date:
Subject: Re: VS2022: Support Visual Studio 2022 on Windows
Next
From: Amit Kapila
Date:
Subject: Re: Added schema level support for publication.