微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Postgresql (psql) .psqlrc技巧和窍门

Set all null fields to NULL:

\pset null 'NULL'

After this,the query results look like this:

select 'test' as test_text,null as test_null;
 test_text | test_null
-----------+-----------
 test| NULL
(1 row)

Set the command history file names for each host and database:

\set HISTFILE ~/.psql_history- :HOST - :dbnAME

After this,the history file naming look like this:

.psql_history-alpha-testdb
.psql_history-localhost-test
.psql_history-10.20.10.101-production
...

Set the number of commands to store in the command history:

\set HISTSIZE 2000

Set timing on and see how long query took:

\timing

psql prompt can be customized to your preference:

\set PROMPT1 '(%n@%M:%>) [%/] > ' \set PROMPT2 ''

After this,the PROMPT1 look like this:

(wwwuser@alpha:5432) [webdb] > 

And PROMPT2 is empty.
Complete information can be found here,under prompting.

Set client encoding:

\encoding unicode

Final .psqlrc file look like this:

'NULL' \set HISTFILE ~/.psql_history- :HOST - :dbnAME \set HISTSIZE 2000 \timing \set PROMPT1 '' \encoding unicode

One additional tip is to add less to PAGER environment variable if you want to use less rather than more. So simply add following row to profile (/etc/profile or ~/.profile):

export PAGER=less

原文地址:https://www.jb51.cc/postgresql/196861.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐