> This page location: Managing Tables > Rename Column
> Full Neon documentation index: https://neon.com/docs/llms.txt

# PostgreSQL RENAME COLUMN: Renaming a column

![PostgreSQL RENAME COLUMN](https://neon.com/postgresqltutorial/postgresql-rename-column-300x254.png?alignright)**Summary**: in this tutorial, you will learn how to use the PostgreSQL `RENAME COLUMN` clause in the `ALTER TABLE` statement to rename one or more columns of a table.

## Introduction to PostgreSQL RENAME COLUMN clause

To rename a column of a table, you use the [`ALTER TABLE`](https://neon.com/postgresql/postgresql-tutorial/postgresql-alter-table) statement with `RENAME COLUMN` clause as follows:

```sql
ALTER TABLE table_name
RENAME COLUMN column_name TO new_column_name;
```

In this statement:

- First, specify the name of the table that contains the column which you want to rename after the `ALTER TABLE` clause.
- Second, provide the name of the column that you want to rename after the `RENAME COLUMN` keywords.
- Third, specify the new name for the column after the `TO` keyword.

The `COLUMN` keyword in the statement is optional therefore you can omit it like this:

```sql
ALTER TABLE table_name
RENAME column_name TO new_column_name;
```

For some reason, if you try to rename a column that does not exist, PostgreSQL will issue an error. Unfortunately, PostgreSQL does not support the `IF EXISTS` option for the `RENAME` clause.

To rename multiple columns, you execute the `ALTER TABLE RENAME COLUMN` statement multiple times, one column at a time:

```sql
ALTER TABLE table_name
RENAME column_name1 TO new_column_name1;

ALTER TABLE table_name
RENAME column_name2 TO new_column_name2;
```

If you rename a column referenced by other database objects such as [views](../postgresql-views), [foreign key constraints](https://neon.com/postgresql/postgresql-tutorial/postgresql-foreign-key), [triggers](../postgresql-triggers), and [stored procedures](https://neon.com/postgresql/postgresql-plpgsql/introduction-to-postgresql-stored-procedures), PostgreSQL will automatically change the column name in the dependent objects.

## PostgreSQL RENAME COLUMN examples

Let's take some examples of using the `ALTER TABLE RENAME COLUMN` statement to rename a column.

### Setting up sample tables

First, [create two new tables](https://neon.com/postgresql/postgresql-tutorial/postgresql-create-table) `customers` and `customer_groups`.

```sql
CREATE TABLE customer_groups (
  id serial PRIMARY KEY,
  name VARCHAR NOT NULL
);
CREATE TABLE customers (
  id serial PRIMARY KEY,
  name VARCHAR NOT NULL,
  phone VARCHAR NOT NULL,
  email VARCHAR,
  group_id INT,
  FOREIGN KEY (group_id) REFERENCES customer_groups (id)
);
```

Then, [create a new view](../postgresql-views/managing-postgresql-views) named `customer_data` based on the `customers` and `customer_groups` tables.

```sql
CREATE VIEW customer_data AS
SELECT
  c.id,
  c.name,
  g.name customer_group
FROM
  customers c
  INNER JOIN customer_groups g ON g.id = c.group_id;
```

### 1) Renaming one column example

The following statement uses the `ALTER TABLE RENAME COLUMN` statement to rename the `email` column of the `customers` table to `contact_email`:

```sql
ALTER TABLE customers
RENAME COLUMN email TO contact_email;
```

### 2) Renaming a column that has dependent objects example

This example uses the `ALTER TABLE RENAME COLUMN` statement to change the `name` column of the `customer_groups` table to `group_name`:

```sql
ALTER TABLE customer_groups
RENAME COLUMN name TO group_name;
```

Note that the name column is used in the `customer_data` view.

Now, you can check whether the change in the `name` column was cascaded to the `customer_data` view:

```text
\d+ customer_data
```

Output:

```
                       View "public.customer_data"
     Column     |       Type        | Modifiers | Storage  | Description
----------------+-------------------+-----------+----------+-------------
 id             | integer           |           | plain    |
 name           | character varying |           | extended |
 customer_group | character varying |           | extended |
View definition:
 SELECT c.id,
    c.name,
    g.group_name AS customer_group
   FROM customers c
     JOIN customer_groups g ON g.id = c.group_id;
```

The output indicates that the `name` column has been changed to `group_name`.

### 3) Using multiple RENAME COLUMN statements to rename multiple columns example

These statements rename two columns `name` and `phone` of the `customers` table to `customer_name` and `contact_phone` respectively:

```sql
ALTER TABLE customers
RENAME COLUMN name TO customer_name;

ALTER TABLE customers
RENAME COLUMN phone TO contact_phone;
```

## Summary

- Use the PostgreSQL `ALTER TABLE...RENAME COLUMN` statement to rename a column.

---

## Related docs (Managing Tables)

- [PostgreSQL Data Types](https://neon.com/postgresql/postgresql-tutorial/postgresql-data-types)
- [Create Table](https://neon.com/postgresql/postgresql-tutorial/postgresql-create-table)
- [Select Into](https://neon.com/postgresql/postgresql-tutorial/postgresql-select-into)
- [Create Table As](https://neon.com/postgresql/postgresql-tutorial/postgresql-create-table-as)
- [SERIAL](https://neon.com/postgresql/postgresql-tutorial/postgresql-serial)
- [Sequences](https://neon.com/postgresql/postgresql-tutorial/postgresql-sequences)
- [Identity Column](https://neon.com/postgresql/postgresql-tutorial/postgresql-identity-column)
- [Generated Columns](https://neon.com/postgresql/postgresql-tutorial/postgresql-generated-columns)
- [Alter Table](https://neon.com/postgresql/postgresql-tutorial/postgresql-alter-table)
- [Rename Table](https://neon.com/postgresql/postgresql-tutorial/postgresql-rename-table)
- [Add Column](https://neon.com/postgresql/postgresql-tutorial/postgresql-add-column)
- [Drop Column](https://neon.com/postgresql/postgresql-tutorial/postgresql-drop-column)
- [Change Column's Data Type](https://neon.com/postgresql/postgresql-tutorial/postgresql-change-column-type)
- [Drop Table](https://neon.com/postgresql/postgresql-tutorial/postgresql-drop-table)
- [Temporary Table](https://neon.com/postgresql/postgresql-tutorial/postgresql-temporary-table)
- [Truncate Table](https://neon.com/postgresql/postgresql-tutorial/postgresql-truncate-table)
- [Copy Table](https://neon.com/postgresql/postgresql-tutorial/postgresql-copy-table)
