Appearance
ybsql Properties
The following properties are predefined options that you can set at run time or in your ybsql startup file (.ybsqlrc). By convention, these properties have uppercase names; avoid using the same names in your user-defined variables. For more information about each property, see Property Details.
| Property Name | Short Description |
|---|---|
| AUTOCOMMIT on | off | Whether individual commands commit when they complete. |
| DBNAME | Current database name. |
| ECHO all | queries | errors | Display setting. |
| ENCODING | Current encoding. |
| FETCH_COUNT number | Number of rows to fetch and display. |
| HISTCONTROL, HISTFILE, HISTSIZE | History file settings. |
| HOST | Current database server host. |
| IGNOREEOF | Behavior when EOFs are sent. |
| ON_ERROR_ROLLBACK, ON_ERROR_STOP | Behavior when errors are returned. |
| PORT | Current database server port. |
| QUIET | Equivalent to -q. |
| SINGLELINE, SINGLESTEP | Equivalent to the -S and -s. |
| USER | Current database user. |
| VERBOSITY default | terse | verbose | Verbosity of error messages. |
To set a property or a variable, use the \set command. To see the its value, use the \echo command with a colon in front of the property or variable name. For example, set the HISTSIZE property and return its value:
premdb=> \set HISTSIZE 100
premdb=> \echo :HISTSIZE
100Property Details
- AUTOCOMMIT
Values are
on(the default) andoff.AUTOCOMMIT onmeans that each SQL command is automatically committed when it completes.AUTOCOMMIT offmeans that SQL commands are not committed until aCOMMITorENDstatement is run explicitly.For example:
premdb=# \set AUTOCOMMIT off premdb=# update season set seasonid=30 where winners is null; UPDATE 1 premdb=# end; COMMITWhen
AUTOCOMMITisoff, you must explicitly abandon any transaction that fails by using anABORTorROLLBACKcommand. If you exit from a session without committing a transaction, all of the changes are lost.Warning: Yellowbrick Data recommends never setting
AUTOCOMMITtooff. Leaving transactions open can have a serious impact on the entire system, such as preventing locks from being released and causing excessive resource consumption.- DBNAME
Name of the currently connected database, which is set on every connection but can be unset.
- ECHO
Set to
all,queries, orerrors. These values are equivalent to the-a,-e, and-boptions, respectively. If unset, or set tonone, no queries are displayed.- ENCODING
The current client character set encoding.
- FETCH_COUNT
An integer value that defines how many query result rows to fetch and display at a time. By default,
ybsqlfetches the entire result set before displaying it.- HISTCONTROL
ignorespace: lines that begin with a space are not saved in the history list.ignoredups: lines that match the previous history line are not saved.ignorebothis a combination of the other two options. If this variable is unset or set tonone, all lines read in interactive mode are saved.- HISTFILE
Name of the file where the history list is stored. The default name is
.ybsql_history(orybsql_historyon Windows). The file is found in the user's home directory on Linux clients and in%APPDATA%\postgresqlon Windows clients.- HISTSIZE
The number of commands to store in the command history. The default value is 500.
- HOST
Database server host for the current connection, which is set on every connection but can be unset.
- IGNOREEOF
Unset: sending an
EOFcharacter (Control+D) to an interactiveybsqlsession causes the application to quit. Set to a numeric value: number ofEOFcharacters that are ignored beforeybsqlquits. If the variable is set but has no numeric value, the default is10. In the following example, the user entersControl+Dthree times beforeybsqlquits:premdb=# \set IGNOREEOF 3 premdb=# Use "\q" to leave ybsql. premdb=# Use "\q" to leave ybsql. premdb=# \q ybuser1@ybuser1:/usr/bin$- ON_ERROR_ROLLBACK
on: if a statement in a transaction block generates an error, ignore the error and continue.interactive: ignore errors only in interactive sessions, not when reading scripts. Unset oroff: a statement in a transaction block that generates an error aborts the whole transaction.- ON_ERROR_STOP
By default, command processing continues when an error occurs.
onortrue: processing stops immediately. In interactive mode,ybsqlreturns to the command prompt; otherwise,ybsqlexits, returning error code 3 to distinguish this case from fatal error conditions, which are reported using error code 1. In either case, any running scripts (the top-level script and any other scripts that it may have invoked) terminate immediately. If the top-level command string contained multiple SQL commands, processing stops with the current command.For example, if the user's startup file (
.ybsqlrc) contains\set ON_ERROR_STOP trueand a SQL script returns an error because a table specified in a command does not exist, the script stops running (and returns error code 3):yellowbrick=# \i premdb.ddl DROP DATABASE CREATE DATABASE You are now connected to database "premdb" as user "yb100". ybsql:premdb.ddl:7: ERROR: table "season" does not exist premdb=# \qIf
ON_ERROR_STOPis not set or set tofalse, the script reports errors but keeps running:yellowbrick=# \i premdb.ddl DROP DATABASE CREATE DATABASE You are now connected to database "premdb" as user "yb100". ybsql:premdb.ddl:7: ERROR: table "season" does not exist ybsql:premdb.ddl:8: ERROR: table "team" does not exist ybsql:premdb.ddl:9: ERROR: table "hometeam" does not exist ybsql:premdb.ddl:10: ERROR: table "awayteam" does not exist ybsql:premdb.ddl:11: ERROR: table "match" does not exist CREATE TABLE CREATE TABLE CREATE TABLE CREATE TABLE CREATE TABLE ...- PORT
Database server port for the current connection, which is set on every connection but can be unset.
- PROMPT1, PROMPT2, PROMPT3
Strings that define the appearance of the
ybsqlprompt.PROMPT1is the normal prompt that is issued whenybsqlstarts or is ready for a new command.PROMPT2is returned when a command is incomplete: for example, because it does not end with a semicolon or is missing a closing quote. Almost any text string enclosed by single quotes that you enter for the prompt value will be displayed as is. However, you can use a number of%escape sequences to plug in specific values for the current user, host, database, and so on.PROMPT3is returned duringCOPY...FROM STDINoperations.See ybsql Prompt Variables for examples and details about customizing prompts.
- QUIET
onis equivalent to the-qoption.- SINGLELINE
onis equivalent to the-Soption.- SINGLESTEP
onis equivalent to the-soption.- USER
Database user for the current connection, which is set on every connection but can be unset.
- VERBOSITY
default,terse, orverboseerror messages. For example:premdb=# \set VERBOSITY verbose premdb=# select * from not_a_table; ERROR: 42P01: relation "not_a_table" does not exist LINE 1: select * from not_a_table; ^ premdb=# \set VERBOSITY terse premdb=# select * from not_a_table; ERROR: relation "not_a_table" does not exist at character 15