Question 5 which bash shortcut or command is used to complete commands, file names, and options?
Connecting to a Databasepsql is a regular PostgreSQL client application. In order to connect to a database you need to know the name of your target database, the host name and port number of the server, and what user name you want to connect as. psql can be told about those parameters via command line options, namely Show
When the defaults aren't quite right, you can save yourself some typing by setting the environment variables An alternative way to specify connection parameters is in a $ This way you can also use LDAP for connection parameter lookup as described in Section 34.18. See Section 34.1.2 for more information on all the available connection options. If the connection could not be made for any reason (e.g., insufficient privileges, server is not running on the targeted host, etc.), psql will return an error and terminate. If both standard input and standard output are a terminal, then
psql sets the client encoding to “auto”, which will detect the appropriate client encoding from the locale settings ( Entering SQL CommandsIn normal operation, psql provides a prompt with the name of the database to which psql
is currently connected, followed by the string $ At the prompt, the user can type in SQL commands. Ordinarily, input lines are sent to the server when a command-terminating semicolon is reached. An end of line does not terminate a command. Thus commands can be spread over several lines for clarity. If the command was sent and executed without error, the results of the command are displayed on the screen. If untrusted users have access to
a database that has not adopted a secure schema usage pattern, begin your session by removing publicly-writable schemas from Whenever a
command is executed, psql also polls for asynchronous notification events generated by While C-style block comments are passed to the server for processing and removal, SQL-standard comments are removed by psql. Advanced FeaturesVariablespsql provides variable substitution features similar to common Unix command shells. Variables are simply name/value pairs, where the value can be any string of any length. The name must consist of letters (including non-Latin letters), digits, and underscores. To set a variable, use the psql meta-command testdb=> sets the variable testdb=> This works in both regular SQL commands and meta-commands; there is more detail in SQL Interpolation, below. If you call NoteThe arguments of A number of these variables are treated specially by psql. They represent certain option settings that can be changed at run time by altering the value of the variable, or in some cases represent changeable state of psql. By convention, all specially treated variables' names consist of all upper-case ASCII letters (and possibly digits and underscores). To ensure maximum compatibility in the future, avoid using such variable names for your own purposes. Variables that control psql's behavior generally cannot be unset or set to invalid values. An The specially treated variables are:
When NoteIn autocommit-off mode, you must explicitly abandon any failed transaction by entering NoteThe autocommit-on mode is PostgreSQL's traditional behavior, but autocommit-off is closer to the SQL spec. If you prefer autocommit-off, you might wish to set it in the system-wide COMP_KEYWORD_CASE Determines which letter case to use when completing an SQL key word. If set to DBNAME The name of the database you are currently connected to. This is set every time you connect to a database (including program start-up), but can be changed or unset. ECHO If set to ECHO_HIDDEN When this variable is set to ENCODING The current client character set encoding. This is set every time you connect to a database (including program start-up), and when you change the encoding with ERROR
FETCH_COUNT If this variable is set to an integer value greater than zero, the results of TipAlthough you can use any output format with this feature, the default HIDE_TABLEAM If this variable is set to HIDE_TOAST_COMPRESSION If this variable is set to HISTCONTROL If this variable is set to NoteThis feature was shamelessly plagiarized from Bash. HISTFILE The file name that will be used to store the history list. If unset, the file name is taken from the \set HISTFILE ~/.psql_history-:DBNAME in
NoteThis feature was shamelessly plagiarized from Bash. HISTSIZE The maximum number of commands to store in the command history (default 500). If set to a negative value, no limit is applied. NoteThis feature was shamelessly plagiarized from Bash. HOST
The database server host you are currently connected to. This is set every time you connect to a database (including program start-up), but can be changed or unset. IGNOREEOF If set to 1 or less, sending an EOF character (usually Control+D) to an interactive session of psql will terminate the application. If set to a larger numeric value, that many consecutive EOF characters must be typed to make an interactive session terminate. If the variable is set to a non-numeric value, it is interpreted as 10. The default is 0. NoteThis feature was shamelessly plagiarized from Bash. LASTOID The value of the last affected OID, as returned from an LAST_ERROR_MESSAGE LAST_ERROR_SQLSTATE The primary error message and associated SQLSTATE code for the most recent failed query in the current psql session, or an empty string and ON_ERROR_ROLLBACK When set to ON_ERROR_STOP By default, command processing continues after an error. When this variable is set to PORT The database server port to which you are currently connected. This is set every time you connect to a database (including program start-up), but can be changed or unset. PROMPT1 PROMPT2 PROMPT3 These specify what the prompts psql issues should look like. See Prompting below. QUIET Setting this variable to ROW_COUNT The number of rows returned or affected by the last SQL query, or 0 if the query failed or did not report a row count. SERVER_VERSION_NAME SERVER_VERSION_NUM The server's version number as a string, for example SHOW_ALL_RESULTS When this variable is set to SHOW_CONTEXT This variable can be set to the values SINGLELINE Setting this variable to SINGLESTEP Setting this
variable to SQLSTATE The error code (see Appendix A) associated with the last SQL query's failure, or USER The database user you are currently connected as. This is set every time you connect to a database (including program start-up), but can be changed or unset. VERBOSITY This variable can be set to the values VERSION VERSION_NAME VERSION_NUM These variables are set at program start-up to reflect psql's
version, respectively as a verbose string, a short string (e.g., SQL InterpolationA key feature of psql variables is that you can substitute (“interpolate”) them into regular SQL statements, as well as the arguments of meta-commands. Furthermore,
psql provides facilities for ensuring that variable values used as SQL literals and identifiers are properly quoted. The syntax for interpolating a value without any quoting is to prepend the variable name with a colon ( testdb=> would query the table When a value is to be used as an SQL literal or identifier, it is safest to arrange for it to be quoted. To quote the value of a variable as an SQL literal, write a colon followed by the variable name in single quotes. To quote the value as an SQL identifier, write a colon followed by the variable name in double quotes. These constructs deal correctly with quotes and other special characters embedded within the variable value. The previous example would be more safely written this way: testdb=> Variable interpolation will not be performed within quoted SQL literals and identifiers. Therefore, a construction such as One example use of this mechanism is to copy the contents of a file into a table column. First load the file into a variable and then interpolate the variable's value as a quoted string: testdb=> (Note that this still won't work if Since colons can legally appear in SQL commands, an apparent attempt at interpolation (that is, The The colon syntax for variables is standard SQL for embedded query languages, such as ECPG. The colon syntaxes for array slices and type casts are PostgreSQL extensions, which can sometimes conflict with the standard usage. The colon-quote syntax for escaping a variable's value as an SQL literal or identifier is a psql extension. PromptingThe prompts psql issues can be customized to your preference. The three variables The value of the selected prompt variable is printed literally, except where a percent sign (
The full host name (with domain name) of the database server, or %m The host name of the database server, truncated at the first dot, or %> The port number at which the database server is listening. %n The database session user name. (The expansion of this value might change during a database session as the result of the command %/ The name of the current database. %~ Like %# If the session user is a database superuser, then a
%p The process ID of the backend currently connected to. %R In prompt 1 normally %x Transaction status: an empty string when not in a transaction block, or %l The line number inside the current statement, starting from % digits
The character with the indicated octal code is substituted. %: name : The value of the psql variable %` command ` The output of %[ ... %] Prompts can contain terminal control characters which, for example, change the color, background, or style of the prompt text, or change the title of the terminal window. In order for the line editing features of Readline to work properly, these non-printing control characters must be designated as invisible by surrounding them with testdb=> \set PROMPT1 '%[%033[1;33;40m%]%n@%/%R%[%033[0m%]%# ' results in a boldfaced ( %w Whitespace of the same width as the most recent output of To insert a percent sign into your prompt,
write NoteThis feature was shamelessly plagiarized from tcsh. Command-Line Editingpsql uses the Readline or libedit library, if available, for convenient line editing and retrieval. The command history is automatically saved when psql exits and is reloaded when psql starts up. Type up-arrow or control-P to retrieve previous lines. You can also use tab completion to fill in partially-typed keywords and SQL object names in many (by no means all) contexts. For example, at the start of a command, typing Tab completion for SQL object names requires sending queries to the server to find possible matches. In some contexts this can interfere with other operations. For example, after $if psql set disable-completion on $endif (This is not a psql but a Readline feature. Read its documentation for further details.) The Which bash shortcut is used to show available options for completing commands file names and options 1 point Comp Tabtab string ESC+?Which Bash shortcut or command is used to complete commands, file names, and options? Pressing Esc+.
Which bash shortcut or command is used to complete commands file names and options 1 point number history pressing Tab pressing ESC+?In the tcsh or bash shell, press the Tab key instead of Esc to complete a filename.
Which bash shortcut or command displays the list of previous commands?The following shortcuts are used for searching for commands in the bash history:. Up arrow key – retrieves the previous command. ... . Ctrl+P and Ctrl+N – alternatives for the Up and Down arrow keys, respectively.. Which bash shortcut or command separates commands on the same line in Linux?'|' can be used to separate commands, so you can give multiple commands in one line.
|