PostgreSQL 9.3 版本的反斜杠命令有少量变化,这里列出几点介绍下:
- Add psql /watch command to repeatedly execute commands (Will Leinweber)
- Add psql command /gset to store query results in psql variables (Pavel Stehule)
- Allow psql /l to accept a database name pattern (Peter Eisentraut)
- Add “Security” label to /psql df+ output (Jon Erdman)
测试一: watch
watch 命令可以重复执行缓冲区的指令,如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
[pg93@redhatB ~]$ psql francs francs psql (9.3beta1) Type "help" for help. francs=> select now()::timestamp(0); now --------------------- 2013-05-27 10:06:20 (1 row) francs=> watch 2 Watch every 2s Mon May 27 10:06:22 2013 now --------------------- 2013-05-27 10:06:22 (1 row) Watch every 2s Mon May 27 10:06:24 2013 now --------------------- 2013-05-27 10:06:24 (1 row) Watch every 2s Mon May 27 10:06:26 2013 now --------------------- 2013-05-27 10:06:26 (1 row)
|
备注: watch 后接的参数为时间参数,表示时间间隔(s),上面时间间隔为 2 秒。
测试二: gset
gset 命令可以存储 psql 的执行结果到 psql 变量中,执行结果必须返回一行,否则变量不会被设置。
1 2 3 4 5 6 7 8 9 10
|
francs=> select 'francs' as name, '2013-05-27' as create_time name | create_time --------+------------- francs | 2013-05-27 (1 row) francs=> gset francs=> echo :name :create_time francs 2013-05-27
|
备注: gset 命令后可以接前缀参数,如下:
1 2 3 4 5 6 7 8 9 10
|
francs=> select 'francs' as name, '2013-05-27' as create_time name | create_time --------+------------- francs | 2013-05-27 (1 row) francs=> gset user_ francs=> echo :user_name :user_create_time francs 2013-05-27
|
测试三: /l
psql 的 /l 命令支持数据库名匹配参数,如下:
9.3 版本 /l 测试
1 2 3 4 5 6 7 8 9 10 11 12 13
|
[pg93@redhatB ~]$ psql psql (9.3beta1) Type "help" for help. postgres= List of databases Name | Owner | Encoding | Collate | Ctype | Access privileges --------+----------+----------+---------+-------+------------------------ francs | postgres | UTF8 | C | C | =Tc/postgres + | | | | | postgres=CTc/postgres + | | | | | francs=C*T*c*/postgres+ | | | | | select_only=c/francs (1 row)
|
备注:之前版本不支持库名匹配参数。第 4 点是关于 df+ 命令增加显示函数的 SECURITY 属性,这里不演示了。但是函数的 SECURITY 属性很有意思,和 Linux 系统 SUID 类似,以后可能做下测试。
原创文章,作者:6024010,如若转载,请注明出处:https://blog.ytso.com/237972.html