So I was running the following queries in the following sequence:
–first–
CREATE VIEW v_customer_info AS
SELECT
cu.customer_id,
cu.first_name || ‘ ‘ || cu.last_name AS name,
a.address,
a.postal_code,
a.phone,
city.city,
country.country
FROM
customer cu
JOIN address a ON cu.address_id = a.address_id
JOIN city ON a.city_id = city.city_id
JOIN country ON city.country_id = country.country_id
ORDER BY
customer_id;
–Second–
SELECT * FROM v_customer_info;
–Third–
ALTER VIEW v_customer_info
RENAME TO v_customer_information;
–forth–
SELECT * FROM v_customer_information;
–fifth–
ALTER VIEW v_customer_information
RENAME COLUMN customer_id TO c_id;
–Sixth–
CREATE OR REPLACE VIEW v_customer_information
AS
SELECT
cu.customer_id,
cu.first_name || ‘ ‘ || cu.last_name AS name,
cu.initials,
a.address,
a.postal_code,
a.phone,
city.city,
country.country
FROM
customer cu
JOIN address a ON cu.address_id = a.address_id
JOIN city ON a.city_id = city.city_id
JOIN country ON city.country_id = country.country_id
ORDER BY
customer_id;
IT gives the following error for the sixth one which is create or replace one:
ERROR: cannot change name of view column “c_id” to “customer_id”
HINT: Use ALTER VIEW … RENAME COLUMN … to change name of view column instead.
SQL state: 42P16
aman0999 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.