美文网首页
postgresql数据导出导入

postgresql数据导出导入

作者: 紫色红色黑色 | 来源:发表于2020-07-10 22:27 被阅读0次

描述

数据导出

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

相关文章

网友评论

      本文标题:postgresql数据导出导入

      本文链接:https://www.haomeiwen.com/subject/ihuvcktx.html