How to RENAME TABLE in Redshift

Galaxy Glossary

How do I rename a table in Amazon Redshift?

RENAME TABLE changes an existing table’s name without touching its data or permissions.

Sign up for the latest in SQL knowledge from the Galaxy Team!
Thank you! Your submission has been received!
Oops! Something went wrong while submitting the form.

Description

What does RENAME TABLE do in Redshift?

ALTER TABLE … RENAME TO changes only the table name. Data blocks, sort keys, distribution style, grants, and statistics stay untouched, so queries switch seamlessly after you update their references.

When should I rename a table?

Rename tables when a feature ships, a data model evolves, or a typo slips through. It keeps naming consistent while avoiding the overhead of creating a new table and copying data.

How do I rename a table?

Basic syntax

Use ALTER TABLE schema.old_name RENAME TO new_name; Run it in a transaction block to guarantee atomicity with downstream updates.

Example: Rename Orders to CustomerOrders

BEGIN;
ALTER TABLE public.orders RENAME TO customer_orders;
COMMIT;

Can I rename and keep dependencies working?

Views, functions, and queries that hard-code the old table name break. Update them or use late-binding views. Foreign keys remain valid because they reference OIDs, not names.

Does renaming lock the table?

Amazon Redshift takes a metadata lock that blocks concurrent DDL but allows reads and writes to continue. The lock usually lasts milliseconds.

Best practices

1) Qualify the schema to avoid collisions. 2) Use transactions. 3) Update BI tools and ORMs immediately. 4) Search Git repos for the old name.

Common mistakes

Forgetting the schema qualifier: Redshift searches the search_path and may rename the wrong table. Always specify schema.table.

Assuming views auto-update: Views store the table name literally. Refresh or recreate them after renaming.

Frequently asked questions

Can I rename a table across schemas?

No. Use ALTER TABLE … SET SCHEMA first, then RENAME TO.

Is RENAME TABLE reversible?

Yes. Run ALTER TABLE new_name RENAME TO old_name. No data movement occurs.

Why How to RENAME TABLE in Redshift is important

How to RENAME TABLE in Redshift Example Usage


--Rename Products to Inventory keeping schema
BEGIN;
ALTER TABLE analytics.products RENAME TO inventory;
COMMIT;

How to RENAME TABLE in Redshift Syntax


ALTER TABLE [IF EXISTS] <schema.old_table>
    RENAME TO <new_table>;

--Ecommerce example
ALTER TABLE IF EXISTS public.orders
    RENAME TO customer_orders;

Parameters:
IF EXISTS – skip error if table missing.
schema.old_table – current qualified name.
new_table – new unqualified name.

Common Mistakes

Frequently Asked Questions (FAQs)

Does RENAME TABLE move data?

No. Only catalog metadata changes, so it finishes instantly regardless of table size.

Can I rename an external table in Redshift Spectrum?

No. DROP the external table definition and CREATE it again with the new name instead.

Want to learn about other SQL terms?