Customize prompt

Moderator: NorbertKrupa

Post Reply
User avatar
fsalvelt
Intermediate
Intermediate
Posts: 54
Joined: Sun Mar 18, 2012 1:34 am

Customize prompt

Post by fsalvelt » Sun Mar 18, 2012 1:37 am

How can I customize the prompt in vsql? Also, once changed is it possible to make it permanent?
Thank, Fred

User avatar
JimKnicely
Site Admin
Site Admin
Posts: 1825
Joined: Sat Jan 21, 2012 4:58 am
Contact:

Re: Customize prompt

Post by JimKnicely » Tue Mar 20, 2012 3:34 pm

Hello,

There are actually three separate prompts in vsql that can be customized. These prompts are linked to variables appropriately name PROMPT1, PROMPT2, and PROMPT3. The variables store strings and special characters that are used to determine how the prompts are displayed on screen.

PROMPT1 is the prompt you see when issuing any new command in vsql.
PROMPT2 is displayed when vsql is expecting more input on a new line when a statement terminator (semicolon) was not entered or an open quote was not closed.
PROMPT3 is shown if you execute a SQL COPY command and Vertica is expecting you to type in the row values.

Here are the most commpn codes and what they represent (taken from Vertica's Programmer's Guide):
  • %M = The full host name (with domain name) of the database server, or [local] if the connection is over a socket, or [local:/dir/name], if the socket is not at the compiled in default location.
    %m = The host name of the database server, truncated at the first dot, or [local].
    %> = The port number at which the database server is listening.
    %n = The database session user name.
    %/ = The name of the current database.
(Refer to Vertica's Programmer's Guide for a complete list)

You can view the current values of the prompt variables via the echo command:

Code: Select all

dbadmin=> \echo :PROMPT1
%/%R%#
dbadmin=> \echo :PROMPT2
%/%R%#
dbadmin=> \echo :PROMPT3
>>
As an example, I want my main prompt to include my username, the port in which I am connected and the '>' character.

Code: Select all

dbadmin=> \set PROMPT1 '%n(%>)>'
dbadmin(5433)>
If you want you want your new definitions to take affect every time you start vsql you can add the set command(s) to the vsqlrc file located in your ~/.vsqlrc file. That is, you would need to add the line "\set PROMPT1 '%n(%>)>'" to the ~/.vsqlrc file.
Jim Knicely

Image

Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.

User avatar
fsalvelt
Intermediate
Intermediate
Posts: 54
Joined: Sun Mar 18, 2012 1:34 am

Re: Customize prompt

Post by fsalvelt » Fri Mar 23, 2012 8:45 pm

Thanks!
Thank, Fred

Post Reply

Return to “vSQL”