postgresql数据导出导入

描述

数据导出

pg_dump -h 127.0.0.1 -p 5432 -U postgres -f ~/Desktop/db.sql test2
# -U用户名 test2数据库名

数据导入

psql -d test2 -f ~/Desktop/db.sql postgres
# postgres用户名

列转行

有表结构如下

create table test (
  name varchar(24),
  a numeric,
  b numeric,
  c numeric
)

转换成

name a 1
name b 1
name c 1
select 
name,
unnest(string_to_array('a'||','||'b'||','||'c',',')) label
unnest(string_to_array(coalesce(a,0)||','||coalesce(b,0)||','||coalesce(c,0),',')) value
from test

引用

https://www.giserdqy.com/database/postgresql/24152/
client-command
backup

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