描述
數(shù)據(jù)導(dǎo)出
pg_dump -h 127.0.0.1 -p 5432 -U postgres -f ~/Desktop/db.sql test2
# -U用戶名 test2數(shù)據(jù)庫(kù)名
數(shù)據(jù)導(dǎo)入
psql -d test2 -f ~/Desktop/db.sql postgres
# postgres用戶名
列轉(zhuǎn)行
有表結(jié)構(gòu)如下
create table test (
name varchar(24),
a numeric,
b numeric,
c numeric
)
轉(zhuǎn)換成
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