gpt4 book ai didi

postgresql - 如何自定义 PostgreSQL/psql 提示符?

转载 作者:行者123 更新时间:2023-11-29 11:18:48 33 4
gpt4 key购买 nike

如何在 PostgreSQL 命令行工具 psql 中自定义提示(最好是在每个用户的启动脚本中)?

特别是,我希望能够更改它,同时仍然包括指示命令是否为多行的字符(例如。=- , ' 等)。

我正在运行 Ubuntu 10.04 (Lucid)、PostgreSQL 8.4.4。

最佳答案

你当然可以customize提示。

来自文档:

The prompts psql issues can becustomized to your preference. Thethree variables PROMPT1, PROMPT2, andPROMPT3 contain strings and specialescape sequences that describe theappearance of the prompt. Prompt 1 isthe normal prompt that is issued whenpsql requests a new command. Prompt 2is issued when more input is expectedduring command input because thecommand was not terminated with asemicolon or a quote was not closed.Prompt 3 is issued when you run an SQL COPY command and you are expected totype in the row values on theterminal.

如果你想在每个用户的基础上设置提示,你可以将 \set 命令添加到用户的 .psqlrc 文件中。

所以,你的 $HOME/.psqlrc 应该是这样的:

\set PROMPT1 '(%n@%M:%>) %`date +%H:%M:%S` [%/] \n%x%# '

关于postgresql - 如何自定义 PostgreSQL/psql 提示符?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3804130/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com