Postgres 常用操作手札

导出表数据到sql文件

pg_dump -h hostname -p 5432 -U username -d database -t tablename > /tmp/file_name.sql

修改列的类型

�alter table applydata_xq alter COLUMN status type bit varying(16);
直接修改为bit varying(num)会抛出

ERROR:  column "status" cannot be cast automatically to type bit varying  
HINT:  You might need to specify "USING status::bit varying(16)".  

删除字段后再添加status字段

alter table applydata_xq drop status;
alter table applydata_xq add status bit varying(16) not null default B'0'::bit(16); 

从文本中直接导入psql终端执行批量执行
cat sql.txt | ~/pg_client/psql -h "dbname= user= password="

postgresql----根据现有表创建新表
create table table_name (like parent_table {INCLUDING|EXCLUDING}{DEFAULTS|CONSTRAINTS|INDEXES|STORAGE|COMMENTS|ALL});

postgres中字符串数据的插入请使用单引号'

你可能感兴趣的:(Postgres 常用操作手札)