1、登陆PostgresQL
psql -U postgres -d postgres
2、创建表users
create table users( id serial, name varchar(20) );
3、增加字段
alter table users add column age int;
4、修改字段类型
alter table users alter column age type varchar(10);
5、修改字段名称
alter table users rename age to school;
6、删除字段
alter table users drop column school;7、删掉字段两边的空格
update users set name = btrim(name);
8、删除重复数据
alter table users add column score int; insert into users values(1, 'zhenqing.wang1', 99); insert into users values(2, 'zhenqing.wang2', 97); insert into users values(3, 'zhenqing.wang3', 99); select ctid, * from users where ctid not in (select max(ctid) from users group by score); delete from users where ctid not in (select max(ctid) from users group by score);
9、导入导出数据
本地导入数据 psql -U postgres -d postgres < /home/zhenqingwang/Desktop/1.sql 本地导出数据 pg_dump -U postgres -d postgres > /home/zhenqingwang/Desktop/1.sql