This article mainly introduces a summary of the common operations of Postgresql ALTER statement. This article explains the code examples of common operations such as adding a column, deleting a column, changing the data type of a column, renaming a table, changing the name of a column, setting not null of a field, etc. Friends who need it can refer to the following
postgresql version: psql (9.3.4)
1. Add a column
ALTER TABLE table_name ADD column_name datatype;
2, delete a column
ALTER TABLE table_name DROP column_name;
3. Change the data type of the column
ALTER TABLE table_name ALTER column_name TYPE datatype;
4. Rename the table
ALTER TABLE table_name RENAME TO new_name;
5. Change the name of the column
ALTER TABLE table_name RENAME column_name to new_column_name;
6. The not null setting of the field
ALTER TABLE table_name ALTER column_name {SET|DROP} NOT NULL;
7. Add default to the column
ALTER TABLE table_name ALTER column_name SET DEFAULT expression;
Quoted from: http://www.jb51.net/article/68421.htm