今天主要分享下psql的元素周期表,下面一起來看看吧~
psql 可謂是最強大的資料庫命令行客戶端,具備以下優點:
postgres=# \\?
1、列出psql 幫助
\\? [commands] show help on backslash commands
\\? options show help on psql command-line options
\\? variables show help on special variables
2、列出SQL COMMAND語法幫助
\\h [NAME] help on syntax of SQL commands, * for all commands
3、對查詢結果進行行列變換
\\crosstabview [ colV [ colH [ colD [ sortcolH ] ] ] ]
Executes the current query buffer (like \\g) and shows the results in a crosstab grid.
create table abc (uid int, class text, score float);
insert into abc select random()*100, (array['語文','數學','英語','物理','化學'])[ceil(random()*5)::int], round((random()*100)::numeric,0) from generate_series(1,500);
select * from abc limit 10;
select class, level, count(*) from (select *,width_bucket(score,0,101,5) as level from abc) t group by 1,2 order by 1,2;
--指定X軸、Y周進行變換,執行前一條SQL(當前query buffer的SQL)。
postgres=# \\crosstabview level class
4、列印當前query buffe
\\p
\\w FILE write query buffer to file
postgres=# select 1;
postgres=# \\p
--將QUERY BUFFER寫入文件
postgres=# \\w '/tmp/abc'
--執行作業系統命令 \\!
postgres=# \\! cat '/tmp/abc'
5、列印所有query buffer(實際上是.psql_history)
\\s [FILE] display history or save it to file
psql還有很多其他用法,篇幅有限,就介紹到這了,覺得有用的朋友多幫忙轉發哦!後面會分享更多devops和DBA方面的內容,感興趣的朋友可以關注下~