2

Let's say I have a table Student with just 2 columns - id bigint, name varchar(50).

I'm trying to rename it and add column in a same single query in PostgreSQL version 11.16 like below:

ALTER TABLE student
  RENAME COLUMN name TO fullname, 
  ADD COLUMN roll_no varchar(30);

But I got this error:

Syntax error at or near "ADD"

Is it possible? If not, why?

4
  • 2
    No, not possible. You could execute two ALTER statements in a single transaction. And why it's not supported? Because nobody has build it yet. Commented Oct 18, 2022 at 11:06
  • 1
    im not sure but maybe that will help you: stackoverflow.com/questions/70176036/… Commented Oct 18, 2022 at 11:09
  • @frank-heikens, But I can add two columns in a single alter query. Commented Oct 18, 2022 at 11:12
  • 2
    @Md.NowshadHasan: Yes, that's correct, you can add multiple columns in a single statement. But not rename and add in a single statement. Just check the manual Commented Oct 18, 2022 at 11:13

1 Answer 1

0

Actually, that is not possible. I got this from the StackOverflow answer. One RENAME is possible for only one statement. Even multiple RENAME commands are also not possible. Here is the postgres manual.

Sign up to request clarification or add additional context in comments.

Comments

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.