Error when renaming a table in RDS for PostgreSQL: relation "xxx" already exists

Updated at:

Problem description

When you run the following SQL statement in an ApsaraDB RDS for PostgreSQL instance to change a table name to uppercase:

alter table testtable rename to TESTTABLE

The following error is returned:

ERROR: relation "testtable" already exists

Cause

By default, table names in ApsaraDB RDS for PostgreSQL are not case-sensitive.

Solution

Enclose the uppercase table name in double quotation marks (""). For example:

alter table testtable rename "TESTTABLE";
Note

You must also use the uppercase table name in subsequent queries.

Applicable to

ApsaraDB RDS for PostgreSQL