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 <host> "dbname=<db_name> user=<username> password=<password>"

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

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

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容