Appearance
ybsql Prompt Variables
You can use the following syntax to customize your ybsql
prompts (PROMPT1
and PROMPT2
variables). The default value for both prompts is '%/%R%# '
. To place a percentage sign in your prompt, use %%
.
Substitution | Description |
---|---|
%M | Full host name of the database server; [local] if the connection is over a Linux domain socket. |
%m | Host name of the database server, truncated at the first dot; [local] if the connection is over a Linux domain socket. |
%> | Port number where the database server is listening. |
%n | The database session user name. (The prompt may change during a session if a SET SESSION AUTHORIZATION command is run.) |
%/ | Name of the current database. |
%~ | Like %/ , but the output is ~ (tilde) if the database is your default database. |
%# | # if the session user is a database superuser; otherwise, > . (The prompt may change during a session if a SET SESSION AUTHORIZATION command is run.) |
%R | PROMPT1 : = , ^ if in single-line mode, ! if the session is disconnected from the database (if \connect fails). PROMPT2 : %R is replaced by one of the following characters:- - if the command was not terminated- * if there is an unfinished /* ... */ comment- ' if there is an unfinished quoted string- " if there is an unfinished quoted identifier- $ if there is an unfinished dollar-quoted string- ( if there is an unmatched left parenthesis |
%x | Transaction status: - An empty string when not in a transaction block - * when in a transaction block- ! when in a failed transaction block- ? when the transaction state is unknown (for example, if there is no connection) |
%l | Line number inside the current statement, starting from 1 . |
%digits | Character with the specified octal code is substituted. For example: %044%040 ($ character, then a space character) |
%:name | Value of the ybsql variable name. See ybsql User Variables. For example: %:ENCODING |
% command`` | Output of the specified command (similar to ordinary "back-tick" substitution). For example: % whoami`` |
%[ ... %] | Prompts can contain terminal control characters that, change the color, background, or style of the prompt text, or the title of the terminal window, for example. Multiple pairs of %[ and %] can occur within the prompt. |
Examples
premdb=# \set PROMPT1 'myprompt '
myprompt
premdb=# \set PROMPT1 '%/%R%# '
premdb=#
premdb=# \set PROMPT1 %044%040
$
$ \set PROMPT1 %n%100%/%044%040
ybuser1@premdb$
ybuser1@premdb$ \set PROMPT1 %M%044%040
[local]$
[local]$ \c premdb bobr
Password for user bobr:
You are now connected to database "premdb" as user "bobr".
premdb=> \set PROMPT1 %n%044%R%040
bobr$=
bobr$= \set PROMPT2 %n%044%R%040
bobr$= select * from team
bobr$- ;
...
ybuser1@ybuser1:/usr/bin$ ./ybsql premdb bobr --set=PROMPT1='bobr_yb '
Password for user bobr:
bobr_yb