snippetsqlCritical
How can I specify the position for a new column in PostgreSQL?
Viewed 0 times
postgresqlcanthenewcolumnpositionforhowspecify
Problem
If I have a table with the columns:
and would like to add a column, I use:
Then the column is added after the
Is there any way I can specify the position for the new column? e.g. so I can add it after
id | name | created_dateand would like to add a column, I use:
alter table my_table add column email varchar(255)Then the column is added after the
created_date column.Is there any way I can specify the position for the new column? e.g. so I can add it after
name and get a table like:id | name | email | created_dateSolution
ALTER TABLE ADD COLUMN will only add the new column at the end, as the last one.In order to create a new column in another position you need to recreate the table and copy the data from the old/current table in this new table.
Context
StackExchange Database Administrators Q#3276, answer score: 113
Revisions (0)
No revisions yet.