본문 바로가기
DB/Oracle

컬럼 순서 바꾸는 방법 postgresql alter column position

by JiGyeong 2021. 3. 15.

새로운 컬럼을 추가하면 맨밑에 새로운 컬럼이 추가된다.

 

mbr_type_cd를 추가했을 경우

 

새로운 컬럼을 중간으로 추가하고 싶을 경우 다음과 같은 방법을 사용하면 된다.

 

1. alter table tablename rename to oldtable;

2. 새로운 newtable 생성 (column postion을 원하는 순으로)

    insert into tablename (col1, col2, col3) select col1, col2, col3 from oldtable

oldtable의 데이터를 newtable에 insert

 

주의사항 ; pk등의 릴레이션 명칭도 변경필요

 

[참고]

stackoverflow.com/questions/285733/how-do-i-alter-the-position-of-a-column-in-a-postgresql-database-table

 

How do I alter the position of a column in a PostgreSQL database table?

I've tried the following, but I was unsuccessful: ALTER TABLE person ALTER COLUMN dob POSITION 37;

stackoverflow.com