postgresql数据导出导入

2020-07-10  本文已影响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

上一篇 下一篇

猜你喜欢

热点阅读