Command summary v41
Use these commands with EDB*Plus.
ACCEPT
The ACCEPT
command displays a prompt and waits for keyboard input. The value from the input is placed in the specified variable.
ACC[EPT ] variable
This example creates a new variable named my_name
, accepts a value of John Smith
, and then displays the value using the DEFINE
command.
SQL> ACCEPT my_name Enter value for my_name: John Smith SQL> DEFINE my_name DEFINE MY_NAME = "John Smith"
APPEND
APPEND
appends the given text to the end of the current line in the SQL buffer.
A[PPEND ] text
In this example, a SELECT
command is built in the SQL buffer using the APPEND
command. Two spaces are placed between the APPEND
command and the WHERE
clause to separate dept
and WHERE
by one space in the SQL buffer.
SQL> APPEND SELECT * FROM dept SQL> LIST 1 SELECT * FROM dept SQL> APPEND WHERE deptno = 10 SQL> LIST 1 SELECT * FROM dept WHERE deptno = 10
CHANGE
CHANGE
performs a search-and-replace on the current line in the SQL buffer.
C[HANGE ] FROM [ TO ]
If you specify TO/
, the first occurrence of the text FROM
in the current line is changed to text TO
. If you omit TO/
, the first occurrence of the text FROM
in the current line is deleted.
This sequence of commands makes line 3 the current line and then changes the department number in the WHERE
clause from 20 to 30.
SQL> LIST 1 SELECT empno, ename, job, sal, comm 2 FROM emp 3 WHERE deptno = 20 4* ORDER BY empno SQL> 3 3* WHERE deptno = 20 SQL> CHANGE /20/30/ 3* WHERE deptno = 30 SQL> LIST 1 SELECT empno, ename, job, sal, comm 2 FROM emp 3 WHERE deptno = 30 4* ORDER BY empno
CLEAR
The CLEAR
command removes the contents of the SQL buffer, deletes all column definitions set with the COLUMN
command, or clears the screen.
CL[EAR ] [ BUFF[ER ] | SQL | COL[UMNS ] | SCR[EEN ] ]
BUFFER | SQL
Clears the SQL buffer.
COLUMNS
Removes column definitions.
SCREEN
Clears the screen. This is the default.
COLUMN
The COLUMN
command controls output formatting. The formatting attributes set by using the COLUMN
command remain in effect only for the current session.
COL[UMN] [column_name [CLE[AR] | FOR[MAT] format_spec | HEA[DING] heading_text | NEW_V[ALUE] variable | ON | OFF...]]
If you specify the COLUMN
command with no other options, formatting options for current columns in effect for the session are displayed.
If the COLUMN
command is followed by a column name, then the column name can be followed by one of the following:
- No other options
CLEAR
- Any combination of
FORMAT
,HEADING
,NEW_VALUE
and eitherOFF
orON
column_name
Name of a column in a table to which column formatting options apply. If no other options follow column_name
, then the current column formatting options of column_name
, if any, are displayed.
CLEAR
The CLEAR
option reverts all formatting options to their defaults for column_name
. If you specify the CLEAR
option, it must be the only option specified.
format_spec
Format specification to apply to column_name
. For character columns, format_spec
takes the following format:
n
n
is a positive integer that specifies the column width in characters within which to display the data. Data in excess of n
wraps around with the specified column width.
For numeric columns, format_spec
is made up of the following elements.
Element | Description |
---|---|
$ | Display a leading dollar sign. |
, | Display a comma in the indicated position. |
. | Marks the location of the decimal point. |
0 | Display leading zeros. |
9 | Number of significant digits to display. |
If loss of significant digits occurs due to overflow of the format, then all #s are displayed.
heading_text
Text to use for the column heading of column_name
.
NEW_V[ALUE]
This variable option is valid if specified alone or with other already supported options. A variable specified in the COLUMN
command option is associated with the given column. The variable can contain the data value of a column or expression of a variable in the SQL SELECT
list. You can use it in the SQL script for the rest of the session.
To contain the departmentnumber
value for the deptno
column, you can define a variable using the NEW_VALUE
option:
SQL> column deptno new_value departmentnumber SQL> select deptno,dname from dept; DEPTNO DNAME ------ -------------- 10 ACCOUNTING 20 RESEARCH 30 SALES 40 OPERATIONS SQL> prompt departmentnumber: '&departmentnumber' departmentnumber: '40' SQL> INSERT INTO emp VALUES (1,'micheal','tester',7902,'17-DEC-80',800,NULL,'&departmentnumber'); 1 row INSERTED.
The NEW_V[ALUE]
variable has the following limitations:
- Column values differ when they're seeded using the
NEW_VALUE
parameter for the "time with time zone" data type. - The
NEW_VALUE
variable prompts for the value if the corresponding column value isNULL
. Oracle treatsNULL
and an empty string the same, while EDB Postgres Advanced Server has a different behavior. Therefore, in EDB*Plus it prompts for the value. - The variable value doesn't show in the
COLUMN
header if you reference theNEW_VALUE
variable in aSELECT
query without an alias.
OFF | ON
If you specify OFF
, formatting options revert to their defaults but are still available in the session. If you specify ON
, the formatting options specified by previous COLUMN
commands for column_name
in the session are reactivated.
This example shows the effect of changing the display width of the job
column:
SQL> SET PAGESIZE 9999 SQL> COLUMN job FORMAT A5 SQL> COLUMN job COLUMN JOB ON FORMAT A5 wrapped SQL> SELECT empno, ename, job FROM emp;
EMPNO ENAME JOB ----- ---------- ----- 7369 SMITH CLERK 7499 ALLEN SALES MAN 7521 WARD SALES MAN 7566 JONES MANAG ER 7654 MARTIN SALES MAN 7698 BLAKE MANAG ER 7782 CLARK MANAG ER 7788 SCOTT ANALY ST 7839 KING PRESI DENT 7844 TURNER SALES MAN 7876 ADAMS CLERK 7900 JAMES CLERK 7902 FORD ANALY ST 7934 MILLER CLERK 14 rows retrieved.
This example applies a format to the sal
column:
SQL> COLUMN sal FORMAT $99,999.00 SQL> COLUMN COLUMN JOB ON FORMAT A5 wrapped COLUMN SAL ON FORMAT $99,999.00 wrapped SQL> SELECT empno, ename, job, sal FROM emp;
EMPNO ENAME JOB SAL ----- ---------- ----- ----------- 7369 SMITH CLERK $800.00 7499 ALLEN SALES $1,600.00 MAN 7521 WARD SALES $1,250.00 MAN 7566 JONES MANAG $2,975.00 ER 7654 MARTIN SALES $1,250.00 MAN 7698 BLAKE MANAG $2,850.00 ER 7782 CLARK MANAG $2,450.00 ER 7788 SCOTT ANALY $3,000.00 ST 7839 KING PRESI $5,000.00 DENT 7844 TURNER SALES $1,500.00 MAN 7876 ADAMS CLERK $1,100.00 7900 JAMES CLERK $950.00 7902 FORD ANALY $3,000.00 ST 7934 MILLER CLERK $1,300.00 14 rows retrieved.
CONNECT
Change the database connection to a different user or connect to a different database. There must be no white space between any of the parameters following the CONNECT
command. The syntax is:
CON[NECT] <username>[/<password>][@{<connectstring> | <variable> } ]
Where:
username
is a database username with which to connect to the database.
password
is the password associated with the specified username. If you don't provide a password, but a password is required for authentication, a search is made for a password file. The search looks first in the home directory of the Linux operating system account invoking EDB*Plus (or in the %APPDATA%\postgresql\
directory for Windows) and then at the location specified by the PGPASSFILE
environment variable. The password file is .pgpass
on Linux hosts and pgpass.conf
on Windows hosts. The following is an example on a Windows host:
C:\Users\Administrator\AppData\Roaming\postgresql\pgpass.conf
If a password file can't be located or it doesn't have an entry matching the EDB*Plus connection parameters, then EDB*Plus prompts for the password. For more information about password files, see the PostgreSQL core documentation.
!!! Note
When a password isn't required, EDB*Plus doesn't prompt for a password, such as when the trust
authentication method is specified in the pg_hba.conf
file. For more information about the pg_hba.conf
file and authentication methods, see the PostgreSQL core documentation.
connectstring
is the database connection string. See Using EDB*Plus for more information about the database connection string.
variable
is a variable defined in the login.sql
file that contains a database connection string. The login.sql
file is in the edbplus
subdirectory of the EDB Postgres Advanced Server home directory.
In this example, the database connection is changed to database edb
on the localhost at port 5445
with username smith
.
SQL> CONNECT smith/mypassword@localhost:5445/edb Disconnected from EnterpriseDB Database. Connected to EnterpriseDB 14.0.0 (localhost:5445/edb) AS smith
In this session, the connection is changed to the username enterprisedb
. The host defaults to the localhost, the port defaults to 5444
(which isn't the same as the port previously used), and the database defaults to edb
.
SQL> CONNECT enterprisedb/password Disconnected from EnterpriseDB Database. Connected to EnterpriseDB 14.0.0 (localhost:5444/edb) AS enterprisedb
This example shows connectivity for a multi-node cluster (one primary node and two secondary nodes) setup. The given multi-host connectstring
syntax is used to establish a connection with the active primary database server. In this case, using CONNECT
command, the connection is established with the primary database node on host 192.168.22.24
at port 5444
.
SQL> CONNECT enterprisedb/edb@192.168.22.24:5444,192.168.22.25:5445,192.168.22.26:5446/edb?targetServerType=primary Disconnected from EnterpriseDB Database. Connected to EnterpriseDB 15.3.0 (192.168.22.24:5444/edb) AS enterprisedb
DEFINE
The DEFINE
command creates or replaces the value of a user variable (also called a substitution variable).