0

I accidentally created a view with a concatenated column and did not alias the column on creation. I would like to fix the alias, but I'm not sure how to alter the view's column since the anonymous reference is not working. Is there a proper way to alter the views column name?

Query to create the view:

CREATE VIEW emp_full_name AS
    SELECT first_name || ' ' || last_name
    FROM employee

Querying the view:

?column?
John Doe
Jane Doe
....

Attempt to update column with new name:

ALTER VIEW emp_full_name RENAME ?column? TO full_name

Error:

LINE 1: ALTER VIEW emp_full_name RENAME ?column? TO full_name

1 Answer 1

1

You can redefine the entire view:

CREATE OR REPLACE VIEW emp_full_name as
    SELECT (first_name || ' ' || last_name) as full_name
    FROM employee;
Sign up to request clarification or add additional context in comments.

3 Comments

I ran your query above and received the following error ERROR: syntax error at or near "AS" LINE 1: ALTER VIEW emp_full_name AS
@cphill . . . as is not used for alter view. It is used for create view.
Ahh thanks for catching that. Still seeing an error with the edited answer ERROR: syntax error at or near "SELECT" LINE 2: SELECT (first_name || ' ' || last_name) as full_name

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.