Overview

Basic Functions

Advanced Features

Table 1 lists the advanced features of gsql.

Table 1 Advanced features of gsql

Feature

Description

Variable

gsql provides a variable feature that is similar to the shell command of Linux. The following \set meta-command of gsql can be used to set a variable:

\set varname value

To delete a variable, run the following command:

\unset varname
NOTE:
  • A variable is a key-value pair. The value length is determined by the special variable VAR_MAX_LENGTH. For details, see Table 2.
  • Variable names must consist of case-sensitive letters (including non-Latin letters), digits, and underscores (_).
  • If the \set varname meta-command (without the second parameter) is used, the variable is set without a value specified.
  • If the \set meta-command without parameters is used, values of all variables are displayed.

For details about variable examples and descriptions, see Variable.

SQL substitution

Common SQL statements can be set to variables using the variable feature of gsql to simplify operations.

For details about SQL substitution examples and descriptions, see Variable.

Customized prompt

Prompts of gsql can be customized. Prompts can be modified by changing the reserved variables of gsql: PROMPT1, PROMPT2, and PROMPT3.

These variables can be set to customized values or the values predefined by gsql. For details, see Variable.

Client operation history record

gsql records client operation history. This function is enabled by specifying the -r parameter when a client is connected. The number of historical records can be set using the \set command. For example, \set HISTSIZE 50 indicates that the number of historical records is set to 50. \set HISTSIZE 0 indicates that the operation history is not recorded.

NOTE:
  • The default number of historical records is 32. The maximum number of historical records is 500. If interactively entered SQL statements contain Chinese characters, only the UTF-8 encoding environment is supported.
  • For security reasons, the records containing sensitive words, such as PASSWORD and IDENTIFIED, are regarded sensitive and not recorded in historical information. This indicates that you cannot view these records in command output histories.

Environment Variables

Table 5 Environment variables related to gsql

Name

Description

COLUMNS

If \set columns is set to 0, this parameter controls the width of the wrapped format. This width determines whether the width output mode is changed to a vertical bar format in automatic expansion mode.

PAGER

If the query result cannot be displayed within one page, the query result will be redirected to the command. You can use the \pset command to disable the pager. Typically, the more or less command is used for viewing the query result page by page. The default value is platform-associated.

NOTE:

Display of the less command is affected by the LC_CTYPE environmental variable.

PSQL_EDITOR

The \e and \ef commands use the editor specified by the environment variables. Variables are checked according to the list sequence. The default editor on Unix is vi.

EDITOR

VISUAL

PSQL_EDITOR_LINENUMBER_ARG

When the \e or \ef command is used with a line number parameter, this variable specifies the command-line parameter used to pass the starting line number to the editor. For editors, such as Emacs or vi, this is a plus sign. A space is added behind the value of the variable if whitespace is required between the option name and the line number. For example:
PSQL_EDITOR_LINENUMBER_ARG = '+'  
PSQL_EDITOR_LINENUMBER_ARG='--line '

A plus sign (+) is used by default on Unix.

PSQLRC

Specifies the location of the user's .gsqlrc file.

SHELL

Has the same effect as the \! command.

TMPDIR

Specifies the directory for storing temporary files. The default value is /tmp.