stella1897
stella1897

Reputation: 57

RENAME column in PostgreSQL

Everywhere I have looked I see that the syntax for renaming a column in PostgreSQL matches what I have done below. But I keep getting an error:

syntax error at or near "RENAME"

This is the code below. The first column I am trying got rename is the primary key. I tried removing that from the code and it still gave the same error. I just need to rename all of these columns.

ALTER TABLE student 
RENAME  student_ID TO stud_student_ID 
RENAME  student_number TO stud_student_number 
RENAME  student_last_name TO stud_student_last_name 
RENAME  student_first_name TO stud_student_first_name 
RENAME  student_city TO stud_student_city 
RENAME  student_state TO stud_student_state 
RENAME  student_5digit_zip char TO stud_student_5digit_zip char
RENAME  date_of_birth TO stud_date_of_birth 
RENAME  start_semester_stud TO stud_start_semester 
RENAME  start_date_stud TO stud_start_date 
RENAME  currently_enrolled TO stud_currently_enrolled 
RENAME  honors_student TO stud_honors_student 
RENAME  overall_gpa TO stud_overall_gpa 
RENAME  credit_hours TO stud_credit_hours 
RENAME  academic_level_id TO stud_academic_level_id 
RENAME  program_id TO stud_program_id 
RENAME  school_id TO stud_school_id 
RENAME  degree_id TO stud_degree_id

Upvotes: -1

Views: 100

Answers (1)

Bohemian
Bohemian

Reputation: 425318

PostgreSQL does not support renaming multiple columns in one statement.

Execute each rename separately:

ALTER TABLE student RENAME student_ID TO stud_student_ID;
ALTER TABLE student RENAME student_number TO stud_student_number;
ALTER TABLE student RENAME student_last_name TO stud_student_last_name;
ALTER TABLE student RENAME student_first_name TO stud_student_first_name;
ALTER TABLE student RENAME student_city TO stud_student_city;
ALTER TABLE student RENAME student_state TO stud_student_state;
ALTER TABLE student RENAME student_5digit_zip char TO stud_student_5digit_zip char;
ALTER TABLE student RENAME date_of_birth TO stud_date_of_birth;
ALTER TABLE student RENAME start_semester_stud TO stud_start_semester;
ALTER TABLE student RENAME start_date_stud TO stud_start_date;
ALTER TABLE student RENAME currently_enrolled TO stud_currently_enrolled;
ALTER TABLE student RENAME honors_student TO stud_honors_student;
ALTER TABLE student RENAME overall_gpa TO stud_overall_gpa;
ALTER TABLE student RENAME credit_hours TO stud_credit_hours;
ALTER TABLE student RENAME academic_level_id TO stud_academic_level_id;
ALTER TABLE student RENAME program_id TO stud_program_id; 
ALTER TABLE student RENAME school_id TO stud_school_id;
ALTER TABLE student RENAME degree_id TO stud_degree_id;

Upvotes: 3

Related Questions